lantunes / fixd

An HTTP Server Fixture for Testing HTTP Clients and mocking web services, and a Java Micro Web Framework
http://bigtesting.org/fixd
Apache License 2.0
41 stars 6 forks source link

Improve performance in relation to asynchronous requests #24

Open lantunes opened 10 years ago

lantunes commented 10 years ago

Currently, an asynchronous request results in a thread-per-request. Replace this approach with another that uses a single additional thread, a Selector, and NIO. The SocketChannel is accessible through the Request.

lantunes commented 10 years ago

Perhaps the user should be given the option of using either the thread-per-asynchronous-request model, or the NIO-based model. Perhaps there may be scenarios where the thread-based model results in better performance?

lantunes commented 10 years ago

The current broadcast-subscribe process with Simple can be improved. Instead of starting a new thread for each subscriber, and having that subscriber thread block on a queue of broadcasts, we can have a single broadcaster thread that starts at startup. Subscribers, with a reference to the Response, register with the broadcaster. This way, the Container can simply create a subscriber and give it to the broadcaster and return immediately.

The same cannot be done for after() and every(). Perhaps these can be improved with an NIO loop that stores the current time (see SelectionKey.attach()) and checks if the required amount of time has elapsed?