This is a creation in Article, where the information may have evolved or changed.
Previously wrote an article: Http://www.cnblogs.com/gengzhe/p/5557789.html, is also the ASP. NET core and Golang Web comparison, enthusiastic friends raised a few questions, as follows:
1, need to join sleep to simulate the actual business, so as to test the co-scheduling ability.
2, Golang is good at multi-core environment.
So I fixed it today and tested it again.
Cpu:e1230-v2
Memory: 16GB
Operating system: CentOS 7 (3 core 2GB memory)
Here's the code:
Go
Package Mainimport ("FMT" "Net/http" "Time") Func main () {FMT. Println ("This is webserver base!") The first parameter is the interface name when the client initiates an HTTP request, and the second parameter is a func that is responsible for processing the request. http. Handlefunc ("/login", Logintask)//server to listen on the host address and port number err: = http. Listenandserve ("192.168.199.236:8081", nil) if err! = Nil {fmt. PRINTLN ("Listenandserve error:", err.) Error ())}}func Logintask (w http. Responsewriter, req *http. Request) {//Gets the parameter Time.sleep (time.millisecond*300) req that the client passed by Get/post. Parseform () fmt. Fprint (W, "Hello word!")}
C#
public class Myhandlermiddleware {//must has constructor with this Signature, otherwise exception at run time public myhandlermiddleware (requestdelegate next) {// This is a HTTP Handler, so no need to store next} public async Task Invoke (HttpContext context) { Await Task.delay (1*300); Await the context. Response.writeasync ("Hello world!"); } // ... } public class Startup {public void configureservices (Iservicecollection services) {}//Th Is method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure (Iapplicationbuilder app) {app. Mapwhen (context = {return context. Request.Path.ToString (). EndsWith ("Jjj.go"); }, AP + = = ap. Usemiddleware<myhandlermiddleware> (); }); } }
Test results (1000 user concurrency)
Go
C#
The test results are really golang a little bit better.
Personal summary of the gap has 2 points
1, Go is static compilation, running speed should be faster.
2.. NET MVC is better packaged, and requests require a lot of processing before entering the business logic.
These are only personal points of view.