Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy don't multiple threads seem to speed up my web application?
    primarykey
    data
    text
    <pre><code>class ApplicationContext{ private final NetworkObject networkObject = new networkObject(); public ApplicationContext(){ networkObject.setHost("host"); networkObject.setParams("param"); } public searchObjects(ObjectType objType){ networkObject.doSearch(buildQuery(objType)); } } class NetworkObject{ private final SearchObject searchObject = new SearchObject(); public doSearch(SearchQuery searchQuery){ searchObject.search(searchQuery); //threadsafe, takes 15(s) to return } } </code></pre> <p>Consider a webserver running a web application which creates only one ApplicationContext instance (singleton) and uses the same applicationInstance to call searchObjects e.g.</p> <pre><code> ApplicationContext appInstance = ApplicationContextFactory.Instance(); //singleton </code></pre> <p>Every new request to a webpage say 'search.jsp' makes a call </p> <pre><code> appInstance.searchObjects(objectType); </code></pre> <p>I am making 1000 requests to 'search.jsp' page. All the threads are using the same ApplicationContext instance, and searchObject.search() method takes 15 seconds to return. My Question is Do all other threads wait for their turn (15 sec) to execute when one is already executing the searchObject.search() function or All threads will execute searchObject.search() concurrently, Why??</p> <p>I hope I have made my question very clear??</p> <p><strong>Update:</strong> Thanks all for clarifying my doubt. Here is my second Question, what difference in performance should be observe when I do:</p> <pre><code>public synchronized doSearch(SearchQuery searchQuery){ searchObject.search(searchQuery); //threadsafe, takes 15(s) to return } </code></pre> <p><strong>OR</strong></p> <pre><code>public doSearch(SearchQuery searchQuery){ searchObject.search(searchQuery); //threadsafe, takes 15(s) to return } </code></pre> <p>I believe using the function 'doSearch' without synchronized keyword should be giving more performance. But, when I tested it today, the results came out the other way. The performance was similar or sometimes better when I use synchronized keyword.</p> <p>Can anyone explain the behavior. How should I debug such cases.</p> <p>Regards,</p> <p>Perry</p>
    singulars
    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.
 

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