先前写过一篇文章:http://www.cnblogs.com/gengzhe/p/5557789.html,也是asp.net core和golang web的对比,热心的园友提出了几点问题,以下:html
一、须要加入sleep来模拟实际业务,这样才能考验协程调度能力。golang
二、golang擅长的是多核环境。web
因而今天修正了一下再次进行测试centos
CPU:E1230-v2服务器
内存:16GB并发
操做系统:centos 7 (3核心2GB内存)app
下面是代码:asp.net
goasync
package main import ( "fmt" "net/http" "time" ) func main() { fmt.Println("This is webserver base!") //第一个参数为客户端发起http请求时的接口名,第二个参数是一个func,负责处理这个请求。 http.HandleFunc("/login", loginTask) //服务器要监听的主机地址和端口号 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) { //获取客户端经过GET/POST方式传递的参数 time.Sleep(time.Millisecond*300) req.ParseForm() fmt.Fprint(w, "Hello Word!") }
C#测试
public class MyHandlerMiddleware { // Must have constructor with this signature, otherwise exception at run time public MyHandlerMiddleware(RequestDelegate next) { // This is an HTTP Handler, so no need to store next } public async Task Invoke(HttpContext context) { await Task.Delay(1*300); await context.Response.WriteAsync("Hello World!"); } // ... } public class Startup { public void ConfigureServices(IServiceCollection services) { } // This 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>(); }); } }
测试结果(1000用户并发)
go
C#
测试结果确实是golang稍微好一点。
我的总结的差距有2点
一、go是静态编译,运行速度按理应该快一些。
二、.NET MVC的封装度更好,请求在进入业务逻辑前须要进行大量的处理。
以上仅为我的观点。