Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Measuring time in a multi-threaded environment is very difficult if you are using simple things like System.nanoTime(). Imagine the following on a 1 core system:</p> <ol> <li>Thread A is woken up and begins processing the incoming request. </li> <li>Thread B is woken up and begins processing the incoming request. But since we are working on a 1 core machine, this ultimately requires that Thread A is put on pause. </li> <li>Thread B is done and performed perfectly fast. </li> <li>Thread A resumes and finishes, but took twice as long as Thread B. Because you actually measured the time it took to finish for Thread A + Thread B.</li> </ol> <p>There are two approaches on how to measure correctly in this case:</p> <ol> <li><p>You can enforce that only one thread is used at all times.<br> This allows you to measure the exact performance of the operation, <strong>if the OS does not interfere.</strong> Because in the above example Thread B can be outside of your program as well. A common approach in this case is to median out the interference, which will give you an <strong>estimation</strong> of the speed of your code.<br>You can however assume, that on an otherwise idle multi-core system, there will be another core to process background tasks, so your measurement will <em>usually</em> not be interrupted. Setting this thread to high priority helps as well.</p></li> <li><p>You use a more sophisticated tool that plugs into the JVM to actually measure the atomic executions and time it took for those, which will effectively remove outside interference almost completely. One tool would be <a href="http://visualvm.java.net/download.html" rel="nofollow">VisualVM</a>, which is already integrated in NetBeans and available as a plugin for Eclipse.</p></li> </ol> <p>As a general advice: it is not a good idea to use more threads than cores, unless you know that those threads will be blocked by some operation frequently. This is not the case when using non-blocking NIO for IO-operations as there is no blocking. </p> <p>Therefore, in your special case, you would actually reduce the performance for clients, as explained above, because communication would be put on hold up to 50% of the time under high load. In worst case, that could cause a client to even run into a timeout, as there is no guarantee when a thread is actually resumed (unless you explicitly request fair scheduling).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload