William,

On 9/7/23 08:04, William Crowell wrote:
When I set -Djdk.tracePinnedThreads=short, then I see this:

…
Thread[#41,ForkJoinPool-1-worker-4,5,CarrierThreads]
     com.mysql.cj.jdbc.ConnectionImpl.isValid(ConnectionImpl.java:2516) <== 
monitors:1
Thread[#39,ForkJoinPool-1-worker-2,5,CarrierThreads]
     com.mysql.cj.jdbc.ConnectionImpl.isValid(ConnectionImpl.java:2516) <== 
monitors:1
Thread[#41,ForkJoinPool-1-worker-4,5,CarrierThreads]
     com.mysql.cj.jdbc.ConnectionImpl.setAutoCommit(ConnectionImpl.java:2005) 
<== monitors:1
Thread[#43,ForkJoinPool-1-worker-5,5,CarrierThreads]
     
com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:893)
 <== monitors:1
     
com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1061)
 <== monitors:1
     
com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1009)
 <== monitors:1
Thread[#43,ForkJoinPool-1-worker-5,5,CarrierThreads]
     com.mysql.cj.jdbc.ConnectionImpl.commit(ConnectionImpl.java:791) <== 
monitors:1
Thread[#43,ForkJoinPool-1-worker-5,5,CarrierThreads]
     com.mysql.cj.jdbc.ConnectionImpl.setAutoCommit(ConnectionImpl.java:2005) 
<== monitors:1
…

I started digging into the MySQL client code: 
https://github.com/mysql/mysql-connector-j/blob/8.0.33/src/main/user-impl/java/com/mysql/cj/jdbc/ConnectionImpl.java

This class is littered with synchronized blocks, so now this makes sense to me 
why virtual threads would take longer than a regular OS thread.

This is precisely the kind of thing I was expecting to see.

If your "application code" (which includes everything your application does, including calling into libraries) contains lots of "synchronized" blocks, then I think this is the situation you will often find yourself in.

I would expect that if you were to increase the size of the virtual thread pool things would start to get better, but in order to truly use virtual threads effectively, you have to track-down and eliminate many uses of synchronized blocks and methods in both your application and the libraries you use.

I wouldn't expect virtual threads to become a very widely-deployed performance-optimization technique in the immediate future. I expect that, eventually, lots of code will be re-written to be more virtual-thread-friendly.

-chris

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to