tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Kerber <>
Subject Re: Performance with many small requests
Date Thu, 07 May 2009 23:05:11 GMT
Andre-John Mas wrote:
> On 7-May-2009, at 17:28, Peter Crowther wrote:
>>> From: David kerber []
>>> The tomcat application simply takes the post request,
>>> does a checksum verification of it, decrypts the
>>> lightly-encrypted data,
>>> and writes it to a log file with the timestamps and site identifiers I
>>> mentioned above.  Pretty simple processing, and it is all inside a
>>> synchronized{} construct:
>>>    protected synchronized void doPost(HttpServletRequest request,
>>> HttpServletResponse response )
>>>            throws ServletException, IOException {
>>>        synchronized ( criticalProcess ) {
>>>            totalReqCount++;
>>>            dailyReqCount++;
>>>            processRequest( request, response, false );
>>>        }
>>>    }
>> Doesn't the "synchronized" in the above mean that you're essentially 
>> single-threading Tomcat?  So you have all this infrastructure... and 
>> that sync may well be the bottleneck.
> That would be my impression too. It is best to avoid making the 
> synchronized scope so large, unless there is a very good reason.
> David, do you have any reason for this? Beyond the counter, what other 
> stuff do you synchronise? Also, it has generally been recommended to 
> me to avoid hitting the disk in every request, since you may result 
> with an I/O bottle neck, so if you can write the logs in batches you 
> will have better performance. If you know that you are only going to 
> have very few users at a time (say, less than 10), it may not be worth 
> the time optimising this, but if you know that you are going to get at 
> least several hundred, then this is something to watch out for.

Thanks for the comments, Andre-John and Peter.  When I wrote that app, I
didn't know as much as I do now, but I'm still not very knowledgeable
about synchronized operations.

The synchronized section doesn't do a whole lot, so it doesn't take long
to process.  My question is, what kinds of operations need to be
synchronized?  All I do is decrypt the data from the POST, send a small
acknowledgement response back to the site, and write the line to the log
file.  Does that sound like something that would need to be
synchronized?  If not, pulling that out would be a really easy test to
see if it helps my performance issue.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message