|
|
||
Jean-Francois Arcand's Blog
«Understanding Grizzly part I: Embedding Grizzly HTTP Web Server in 5 lines |
Main
| epoll my Grizzly on Linux »
Understanding Grizzly part II: Adding your own thread poolPosted by jfarcand on December 11, 2006 at 12:03 PM | Comments (2)When embedding Grizzly, being able to replace the default thread pool with an external one is important. Fortunately, this is simple to do. Before going into the details,in Grizzly a thread pool is named a Pipeline. A pipeline is just a wrapper around a thread pool, with some extra methods to collect statistics. The most important methods are execute and waitForIoTask.
The default Grizzly framework ship with two thread pool, one based on a synchronized LinkedList (LinkedListPipeline), one based on Java 5 concurrent API(ThreadPoolExecutorPipeline). By default,Grizzly uses the LinkedListPipeline because this very simple thread pool perform much better than any Java 5 concurrent based API. I know it sound strange, but all the benchmarks we did demonstrated that a simple synchronize/wait/notify thread pool always gives better result. Doesn't agree? I will change the default Pipeline the day I will see a Java 5 concurrent based performing better than the LinkedListPipeline :-) :-) Back to work, configuring the Pipeline is very simple. To demonstrate it, I will re-use the example I've used in part I: By default, Grizzly uses the processor pipeline for processing the request(reading bytes) and the response(writing bytes). For synchronous requests, executing the read and the write operations on the same thread proved to be the best configuration. What about asynchronous requests? Depending on what you are doing with Grizzly, you might want to use a thread for read operations, and a different one for write operations. You may want to use the same thread pool or use two separate one. This is simple to do: With the above configuration, the read operations will be executed using one thread pool, and write operations using a different thread pool. OK next time I will describe how to extends Grizzly to implement any tcp protocol via the StreamAlgorithm interface. technorati: grizzly web server embedded Bookmark blog post: CommentsComments are listed in date ascending order (oldest first) | Post Comment
| ||
|
|