A simple web Server Based on AIO

Source: Internet
Author: User

Here is a simple web Server Based on AIO. This is a simple example.


 
/*** A simple web server <br/> * enter localhost in the browser: 8080/access ** @ author Joeson * @ since 2014/05 **/public class AioServer implements Runnable {private AsynchronousChannelGroup asyncChannelGroup; private AsynchronousServerSocketChannel server; public AioServer (int port) throws Exception {// create a thread pool ExecutorService executor = Executors. newFixedThreadPool (20); // asynchronous channel manager asyncChannelGroup = AsynchronousChannelGroup. wi ThThreadPool (executor); // creates an asynchronous Socket for the server. This is short for server socket. // Asynchronous channel manager, which sets the server parameter server = AsynchronousServerSocketChannel. open (asyncChannelGroup ). bind (new InetSocketAddress (port);} public void run () {try {// specify the receiving operation object for the server socket. the accept prototype is: // accept (A attachment, CompletionHandler <AsynchronousSocketChannel ,//? Super A> handler) // that is, the type A parameter of CompletionHandler here is the first parameter actually used to call the accept method // that is, listener. Another parameter V is the client socketserver in the prototype. accept (server, new CompletionHandler <AsynchronousSocketChannel, AsynchronousServerSocketChannel> () {String str = "



The concurrency of web Servers Based on AIO is higher than that of NIO and Netty. This is mainly because the I/O processing model based on Proactor transfers read/write operations to the right operating system.



(Of course, the static page here is relatively small, saving time in transmission, but it will not have a great impact)

Server concurrency Based on Netty and nio can process more than 6-7 requests per second. However, if AIO is used, it can handle more than 9000 requests (marked by my machine ), tomcat is also a finished product of about 9000, all marked with the same static page.


I have to say that the asynchronous processing of AIO is still very powerful, but it may be worse than NIO in terms of Server Load balancer processing control.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.