This is a creation in Article, where the information may have evolved or changed.
The company now has a restful architecture for search services using Java + jetty; Jetty's simplicity and efficiency has always been a favorite, the restful architecture of search has been stable for two years, but the soft load keepalived want to add some business control module, but keepalived no special development interface, their new development of a set? High cost and performance, stability requirements, consider Scala, Lisp, C are not suitable, need development cycle, performance must be taken into account, go language came out also more than two years, so to pay attention to; The following is the performance test of Go comparison jetty. (Note: The Web of the go language does not have the concept of a service container, no Apache or nginx, etc., at least in the first phase)
The test content is simple, go and Java are a "Hello World" web output
Go code
Package Mainimport ("FMT" "Log" "Net/http" "strings") Func Sayhelloname (w http. Responsewriter, R *http. Request) {r.parseform ()//parameter resolution for K, V: = Range R.form {fmt. Println ("Key:", K) fmt. Println ("Value:", strings. Join (V, ""))}fmt. fprintf (w, "Hello Astaxie")}func Main () {http. Handlefunc ("/", sayhelloname) Err: = http. Listenandserve (": 9090", nil) if err! = Nil {log. Fatal ("Listenandserver", Err)}}
Java code
Package Com.search5173.jetty.test;import Java.io.ioexception;import Javax.servlet.servletexception;import Javax.servlet.http.httpservletrequest;import Javax.servlet.http.httpservletresponse;import Org.eclipse.jetty.server.connector;import Org.eclipse.jetty.server.handler;import Org.eclipse.jetty.server.request;import Org.eclipse.jetty.server.server;import Org.eclipse.jetty.server.handler.abstracthandler;import Org.eclipse.jetty.server.handler.contexthandler;import Org.eclipse.jetty.server.nio.selectchannelconnector;import Org.eclipse.jetty.util.thread.QueuedThreadPool; public class onecontext{public static void Main (string[] args) throws Exception {Queuedthreadpool Threadpoo L= new Queuedthreadpool (); Threadpool.setmaxthreads (11); Threadpool.setminthreads (4); Server server = new server (); Server.setthreadpool (ThreadPool); Connector connector=new selectchannelconnector (); Connector.setport (8081); Server.sEtconnectors (New Connector[]{connector}); Contexthandler context = new Contexthandler (); Context.setcontextpath ("/t"); Context.setresourcebase ("."); Context.setclassloader (Thread.CurrentThread (). Getcontextclassloader ()); Server.sethandler (context); Handler handler=new Hellohandler (); Context.sethandler (handler); Server.start (); Server.join (); } public static class Hellohandler extends Abstracthandler {@Overridepublic void handle (String arg0, Request req Uest1, HttpServletRequest request,httpservletresponse response) throws IOException, Servletexception {response . Getwriter (). println ("<H1>HELLODFGDFGDFGFD onecontext
Test the way Apache AB, this simple and convenient
Test hardware
Pentium (R) dula-core CPU E5200 @2.50ghz
Memory: 3.25GB
Operating system: 32-bit (Win7)
Test address
1) Go--->http://localhost:9090/rwer
2) Java--->http://localhost:8081/t
Test Script One
1) ab-n 50-c http://localhost:9090/rwer
2) ab-n 50-c http://localhost:8081/t
Requests per second: results:
Jetty |
Go |
1311.44 |
2265.21 |
1083.40 |
2491.78 |
1423.85 |
1607.61 |
|
|
Can say in all aspects go all win, know go he strong, but didn't think so strong, impact very big.
And look at some other.
Go
Jetty