Thread: [Simpleweb-Support] parallelism?
Brought to you by:
niallg
From: Juraj B. <ast...@gm...> - 2007-01-16 18:04:21
|
Hello, I am writing a ProtocolHandler, which basically works, but is quite slow. I would like to ask, if handle() method is launched in separate thread or not (i.e. if it can block, or I should create a new Thread and do my work there). I have an application, which have two states, in one, it can return from handle immediately (returning static redirect) and in other mode, it has to block, so I would like to manage, when to create new thread and when not in a new thread (it is not a good idea to create new thread just for returning simple static string). Is there some performance tuning howto? I would like to handle thousands of connections. One part of my application is a reverse proxy. Has someone done that before? Currently I am using new socket per request, which is of course not very effective... Thank you, Juraj. |
From: Niall G. <gal...@ya...> - 2007-01-16 20:23:49
|
Hi, The responses will seem slow if you have set a bad default wait peroid. This is the length of time an inactive connection is put to sleep. So, if you open the connection and don't write anything for a couple of milliseconds then the connection is put to sleep. To configure this property the following can be used: ProtocolHandler myProtocolHandler = new MyProtocolHandler(); PipelineHandler handler = PipelineHandlerFactory.getInstance(myProtocolHandler, 20, 100); This will set the default wait to 100 milliseconds. So responses should be quicker. Also, much of the effort of handling a connection is put into setting up the connection for pipelining (i.e many requests per connection). So request per socket is not going to work well. With regards to the request and response events sent to the pipeline handler they are sent my many threads so you should not synchronize the protocol handler as this will cause blocking and thus serialization of your request processing. Also, why are you creating a new thread within the protocol handler??? If you want to use it as a reverse proxy you are better off sending the request with the thread dispacthed to the protocol handler, and then queuing request socket. After the request is sent you can queue the socket and have another thread pool read in the response perform some processing/translation of the response and deliver it over the socket. This would ensure that you do not limit the number of outstanding request with the number of threads used in the server. Niall --- Juraj Bednar <ast...@gm...> wrote: > Hello, > > I am writing a ProtocolHandler, which basically > works, but is quite > slow. I would like to ask, if handle() method is > launched in separate > thread or not (i.e. if it can block, or I should > create a new Thread > and do my work there). > > I have an application, which have two states, in > one, it can return > from handle immediately (returning static redirect) > and in other mode, > it has to block, so I would like to manage, when to > create new thread > and when not in a new thread (it is not a good idea > to create new > thread just for returning simple static string). > > Is there some performance tuning howto? I would > like to handle > thousands of connections. > > One part of my application is a reverse proxy. Has > someone done that > before? Currently I am using new socket per request, > which is of > course not very effective... > > > Thank you, > > Juraj. > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get > the chance to share your > opinions on IT & business topics through brief > surveys - and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Simpleweb-Support mailing list > Sim...@li... > https://lists.sourceforge.net/lists/listinfo/simpleweb-support > Niall Gallagher ____________________________________________________________________________________ Have a burning question? Go to www.Answers.yahoo.com and get answers from real people who know. |
From: Juraj B. <ast...@gm...> - 2007-01-17 12:20:55
|
Hello, thank you for your last reply. > The responses will seem slow if you have set a bad > default wait peroid. This is the length of time an > inactive connection is put to sleep. So, if you open > the connection and don't write anything for a couple > of milliseconds then the connection is put to sleep. > To configure this property the following can be used: > > ProtocolHandler myProtocolHandler = new > MyProtocolHandler(); > > PipelineHandler handler = > PipelineHandlerFactory.getInstance(myProtocolHandler, > 20, 100); Thank you, this will probably help. So one question, if I read from protocol Request input stream, will it block? > With regards to the request and response events sent > to the pipeline handler they are sent my many threads > so you should not synchronize the protocol handler as > this will cause blocking and thus serialization of > your request processing. Also, why are you creating a > new thread within the protocol handler??? I thought, that I have to exit from handler as soon as possible, because I thought other events are processed from the pipeline by the same thread, but it's because I was evaluating http://docs.safehaus.org/display/ASYNCWEB/Home I've read that documentation and mixed it up. I've fixed it up. My protocol handler is not synchronized, but the question is, does Simple do some requests statistics? (I need connections per second). Creating a new thread just for incrementing counter does not seem to be a good idea to me and it has to be synchronized. If I could get that information from the pipeline, it would be great. > If you want to use it as a reverse proxy you are > better off sending the request with the thread > dispacthed to the protocol handler, and then queuing > request socket. Are there some classes, that would enable me to do this? (MessageQueue)? I'm just studying javadocs, but there are plenty of classes and it takes a while to get the whole picture. > After the request is sent you can > queue the socket and have another thread pool read in > the response perform some processing/translation of > the response and deliver it over the socket. This > would ensure that you do not limit the number of > outstanding request with the number of threads used in > the server. Yes, that's what I would like to do. Thanks, Juraj. |