Fast NIO, asynchronous HTTP Server for Java [close

2019-03-11 15:21发布

Following on this question I am actually in the phase of finding the right HTTP container for one of my projects, too. I looked at several containers but I'm still not sure which one will be best suited for high load AJAX only requests. Apache Mina looks quite promising, but relatively complex as well. The asynchronous web server implementation called AsyncWeb seems to have been merged with Mina but I couldn't find any production relase of it, yet. In the other question I recommended the Simple HTTP server which I really like because it is... well simple, clear and clean but I still don't know if it would fit the purpose.

Additionally I'm not sure on which request handling concept to choose:

  1. Create a dispatcher Thread for every incoming connection (optimizations might of course include a thread pool and a dispatching queue), that is doing all the work. The advantage is probably, that I don't have to deal with that many synchronisation issues but it will probably lower the throughput on high loads drastically.

  2. Because it is going to be a highly modular application a "pipelining" (there might be a more fitting term I guess ;) approach might work as well: Create a fixed number of Threads, each for a certain task. E.g. one for request handling -> one for header deserialization (if I get input in different formats like subtmitted HTML Forms, XML-RPCs, JSON etc.) -> one for "Controller Dispatching" (doing whatever I want to do with these data) -> and one for serializing the output in the desired format (JSON, XML, HTML etc.) and move every request through these levels until it is completed. Probably more difficult to realize but I have a fixed number of Threads (the number can dependend on the hardware as well) and a clean separation of concerns.

Any experiences with any Framework that might fit and the two different handling approaches?

2条回答
混吃等死
2楼-- · 2019-03-11 15:52

There is an example on the Simple HTTP subversion repository.

http://simpleweb.svn.sourceforge.net/viewvc/simpleweb/trunk/src/demo/java/org/simpleframework/example/javafx/

It demonstrates realtime market data using comet and only one thread dispatching updates to any number of clients. Simple has a transparent transport layer that provides blocking I/O semantics with the advantage of asynchronous dispatch with NIO based around fixed ByteBuffer queues for each connected client. So you get a smooth transparent NIO output with predictable memory consumption. Also performance measurements against servers like Jetty show about a x2 performance improvement.

http://simpleweb.svn.sourceforge.net/viewvc/simpleweb/trunk/application/Plotter/ApacheBench/ScalabilityApacheBench.png?revision=1448

查看更多
戒情不戒烟
3楼-- · 2019-03-11 15:52

You may want to look at Jetty, and in particular, Hightide

Hightide is pre-configured with state-of-the-art Ajax communication libraries such as DWR, ActiveMQ-Web (JMS to the browser), and the Bayeux protocol (also known as cometd). Deploying your applications on Hightide means that it will scale smoothly thanks to a combination of Jetty's smart IO layer and continuations mechanism

Specifically, a lot of work has been put in to optimise Jetty for AJAX. See this blog entry for more details

查看更多
登录 后发表回答