asp.net core VS goang web[修正篇]

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。

先前寫過一篇文章:http://www.cnblogs.com/gengzhe/p/5557789.html,也是asp.net core和golang web的對比,熱心的園友提出了幾點問題,如下:

1、需要加入sleep來類比實際業務,這樣才能考驗協程調度能力。

2、golang擅長的是多核環境。

於是今天修正了一下再次進行測試

CPU:E1230-v2

記憶體:16GB

作業系統:centos 7 (3核心2GB記憶體)

下面是代碼:

go

package mainimport ("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點

1、go是靜態編譯,運行速度按理應該快一些。

2、.NET MVC的封裝度更好,請求在進入商務邏輯前需要進行大量的處理。

以上僅為個人觀點。

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.