zoukankan      html  css  js  c++  java
  • net core VS goang web

    先前写过一篇文章: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

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    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#

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    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的封装度更好,请求在进入业务逻辑前需要进行大量的处理。

    以上仅为个人观点。

  • 相关阅读:
    newusers和chpasswd
    docker container link
    ambassador docker container linking
    Forwarding a Range of Ports in VirtualBox
    NekoHTML and Dom4j
    MySQL DATE_FORMAT() 函数
    POJ 1236 Network of Schools(强连通缩点)
    HDU 1269 迷宫城堡(强连通)
    Codeforces 581C Developing Skills
    HDU 3849(桥)
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/5562116.html
Copyright © 2011-2022 走看看