-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Peter,

On 5/8/2009 7:26 AM, Peter Crowther wrote:
> Decrypt: parallel.
> Send ack: parallel.
> Increment counters: synced.
> Write to log file: synced (or you'll have some very odd stuff happening).

I'd go further and suggest that you re-factor your design so that your
servlet is very simple. Something like this:

public void doPost(HttpServletRequest request,
                   HttpServletResponse response)
  throws IOException, ServletException
{
   RequestCounter counter = ...; // get from app scope? Class-level?
   RequestLogger logger = ...; // same here
   RequestProcessor processor = ...; // same here

   counter.count();

   processor.processRequest(request, response, false);

   logger.log(request, response);
}

Then its up to the RequestCounter to maintain its own synchonization (if
necessary) instead of your servlet having to know the semantics of
thread-safety, etc. Same with the logger. As someone mentioned, most
logging frameworks handle synchronization for you, and most of them can
buffer the output to their log files so that you are getting the best
performance you can.

I highly recommend using a logging framework, or developing something
that meets your needs that is self-contained, can accept log entries
from multiple concurrent clients (your servlets), and buffers output to
the log file to keep performance up.

What is it that processRequest actually does? Decryption? Hmm... is it
possible for you to save the decryption for later? You could have a
service that simply logs the notifications and then have a batch job
that later does the decryption and throws-out all the
incorrectly-encrypted data. Just another option.

Finally... if you are logging all requests, is it necessary to keep a
daily and total request count? You can avoid the synchronization of
those counters entirely by ... not bothering to count them. Again,
retrospective counting is a possibility.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkoIkLoACgkQ9CaO5/Lv0PAingCbBNb5ESoaIlDwoROOFrjmYySZ
X94AniMh23cbmU2rodDw5fFISpRwDyhS
=fB6Z
-----END PGP SIGNATURE-----

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

Reply via email to