Bug 64156 - Tomcat 7 Performance: acceptor thread bottleneck at getPoolSize() located at TaskQueue offer function
Summary: Tomcat 7 Performance: acceptor thread bottleneck at getPoolSize() located at ...
Status: RESOLVED DUPLICATE of bug 64155
Alias: None
Product: Tomcat 7
Classification: Unclassified
Component: Catalina (show other bugs)
Version: trunk
Hardware: All All
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-02-18 18:33 UTC by Torres Yang
Modified: 2020-02-21 21:21 UTC (History)
0 users



Attachments
Improved Tomcat 7 performance by reduced number of getPoolSize() call that located at TaskQueue offer function (1.52 KB, patch)
2020-02-18 18:34 UTC, Torres Yang
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Torres Yang 2020-02-18 18:33:14 UTC
Tomcat 7 Performance:

During our performance testing, we found out that the acceptor thread bottleneck at the getPoolSize() located at TaskQueue offer function, which is an expensive call to AbstractQueuedSynchronizer acquire lock. 


Proposed fix is to store and use poolSize as local variable. This reduces 2-3 expensive calls down to 1 for each request.

    @Override
    public boolean offer(Runnable o) {
      //we can't do any checks
      if (parent == null) return super.offer(o);
      // getPoolSize() is expensive call to AbstractQueuedSynchronizer acquire lock
      final int poolSize = parent.getPoolSize();
      //we are maxed out on threads, simply queue the object
      if (poolSize == parent.getMaximumPoolSize()) return super.offer(o);
      //we have idle threads, just add it to the queue
      if (parent.getSubmittedCount() <= poolSize) return super.offer(o);
      //if we have less threads than maximum force creation of a new thread
      if (poolSize < parent.getMaximumPoolSize()) return false;
      //if we reached here, we need to add it to the queue
      return super.offer(o);
    }
Comment 1 Torres Yang 2020-02-18 18:34:43 UTC
Created attachment 37023 [details]
Improved Tomcat 7 performance by reduced number of getPoolSize() call that located at TaskQueue offer function
Comment 2 Mark Thomas 2020-02-21 21:21:06 UTC

*** This bug has been marked as a duplicate of bug 64155 ***