BeetleXとAsp.NetCoreのwebapi基礎性能比較

15924 ワード

本文は主にBeetleXとAspに対して.NetCoreの基礎WebApi機能性能比較

テスト環境の説明

    :E1230V2 16G   10Gb  

    :Windows server 2008 R2 + .Net Core 2.15     :bombardier.exe 

機能コードのテスト


テストの基礎機能の一貫性を確保するために、すべてのテストのurlと要求出力内容が一致します.以下、BeetleXおよびAspについて説明する.NetCoreが実現するWebaApi基礎機能コード:

asp.net core mvc webapi

    public class HomeController : Controller
    {

        public class JsonMessage
        {
            public string message { get; set; }
        }

        public string plaintext()
        {
            return "Hello, World!";
        }

        public object json()
        {
            return new JsonMessage { message = "Hello, World!" };
        }

        public Employee Employee(int id)
        {
            Employee result = DataHelper.Defalut.Employees.Find(e => e.EmployeeID == id);
            if (result == null)
                result = new Employee();
            return result;
        }

        public object Orders(int id, string customerid, int index, int size)
        {
            Funcbool> exp = o => (id == 0 || o.EmployeeID == id)
             && (string.IsNullOrEmpty(customerid) || o.CustomerID == customerid);
            int count = DataHelper.Defalut.Orders.Count(exp);
            if (size == 0)
                size = 10;
            int pages = count / size;
            if (count % size > 0)
                pages++;
            var items = DataHelper.Defalut.Orders.Where(exp).Skip(index * size).Take(size);
            return items;
        }
    }

beetlex webapi

    [Controller(BaseUrl = "Home")]
    public class Controller
    {
        public class JsonMessage
        {
            public string message { get; set; }
        }

        public object plaintext()
        {
            return new TextResult("Hello, World!");
        }

        public object json()
        {
            return new JsonResult(new JsonMessage { message = "Hello, World!" });
        }
        [Get(Route = "{id}")]
        public object Employee(int id)
        {
            Employee result = DataHelper.Defalut.Employees.Find(e => e.EmployeeID == id);
            if (result == null)
                result = new Employee();
            return new JsonResult(result);
        }
        [Get(Route = "{id}")]
        public object Orders(int id, string customerid, int index, int size)
        {
            Funcbool> exp = o => (id == 0 || o.EmployeeID == id)
             && (string.IsNullOrEmpty(customerid) || o.CustomerID == customerid);
            int count = DataHelper.Defalut.Orders.Count(exp);
            if (size == 0)
                size = 10;
            int pages = count / size;
            if (count % size > 0)
                pages++;
            var items = DataHelper.Defalut.Orders.Where(exp).Skip(index * size).Take(size);
            return new JsonResult(items);

        }
    }

テストモード


bombardier.を通るexeツールは、2つのサービスに対して100接続を開き、1000000回のリクエスト応答テストを行います.テストurlは次のとおりです.
/home/plaintext //       Hello, World!  
/home/json          //       Hello, World! json  
/home/employee/3   //       json  
/home/orders/3?index=0&size=5 //           json   

テスト結果


テスト結果から見ると、最も基本的なコンテンツの出力は主にネットワーク処理に関するものであり、この点でBeetlex webapiは絶対性能の優位性があり、Aspと言える.NetCore webapiは2倍以上高い.しかし、いくつかのjson処理機能を追加するにつれて論理処理の占有率が高いと性能の違いは非常に際立っていない(Newtonsoft.Jsonがjsonを処理する際に.net coret自身の処理が効率的ではないことも説明されている)が、後で注文リストに戻ったときでも2倍の性能優位性を備えている.BeetleXの処理能力をさらにテストするために、テストコードをTechEmpower/frameworkBenchmarksに提出しました.次のテストではBeetleXの姿が見えるはずです.

テスト結果詳細


asp core webapi

D:\>bombardier.exe -c 100 -n 10000000 "http://192.168.2.18:8080/home/plaintext"
Bombarding http://192.168.2.18:8080/home/plaintext with 10000000 request(s) usin
g 100 connection(s)
 10000000 / 10000000 [==========================================] 100.00% 2m14s
Done!
Statistics        Avg      Stdev        Max
  Reqs/sec     74691.94    3817.11  114988.50
  Latency        1.33ms   488.74us   385.02ms
  HTTP codes:
    1xx - 0, 2xx - 10000000, 3xx - 0, 4xx - 0, 5xx - 0
    others - 0
  Throughput:    17.38MB/s
D:\>bombardier.exe -c 100 -n 10000000 "http://192.168.2.18:8080/home/json"
Bombarding http://192.168.2.18:8080/home/json with 10000000 request(s) using 100
 connection(s)
 10000000 / 10000000 [==========================================] 100.00% 2m24s
Done!
Statistics        Avg      Stdev        Max
  Reqs/sec     69093.60    3770.80   83161.12
  Latency        1.44ms   549.52us   385.02ms
  HTTP codes:
    1xx - 0, 2xx - 10000000, 3xx - 0, 4xx - 0, 5xx - 0
    others - 0
  Throughput:    17.13MB/s
D:\>bombardier.exe -c 100 -n 10000000 "http://192.168.2.18:8080/home/employee/3"

Bombarding http://192.168.2.18:8080/home/employee/3 with 10000000 request(s) usi
ng 100 connection(s)
 10000000 / 10000000 [==========================================] 100.00% 3m15s
Done!
Statistics        Avg      Stdev        Max
  Reqs/sec     51224.14    2667.55   57796.82
  Latency        1.95ms   637.04us   415.02ms
  HTTP codes:
    1xx - 0, 2xx - 10000000, 3xx - 0, 4xx - 0, 5xx - 0
    others - 0
  Throughput:    29.16MB/s
D:\>bombardier.exe -c 100 -n 10000000 "http://192.168.2.18:8080/home/orders/3?in
dex=0&size=5"
Bombarding http://192.168.2.18:8080/home/orders/3?index=0&size=5 with 10000000 r
equest(s) using 100 connection(s)
 10000000 / 10000000 [===========================================] 100.00% 5m7s
Done!
Statistics        Avg      Stdev        Max
  Reqs/sec     32481.62    1568.13   36897.79
  Latency        3.07ms     2.13ms   600.03ms
  HTTP codes:
    1xx - 0, 2xx - 10000000, 3xx - 0, 4xx - 0, 5xx - 0
    others - 0
  Throughput:    57.96MB/s

beetlex webapi

D:\>bombardier.exe -c 100 -n 10000000 "http://192.168.2.18:9090/home/plaintext"
Bombarding http://192.168.2.18:9090/home/plaintext with 10000000 request(s) usin
g 100 connection(s)
 10000000 / 10000000 [============================================] 100.00% 41s
Done!
Statistics        Avg      Stdev        Max
  Reqs/sec    239341.58   39420.70  261535.62
  Latency      413.11us     1.02ms   396.02ms
  HTTP codes:
    1xx - 0, 2xx - 10000000, 3xx - 0, 4xx - 0, 5xx - 0
    others - 0
  Throughput:    41.56MB/s
D:\>bombardier.exe -c 100 -n 10000000 "http://192.168.2.18:9090/home/json"
Bombarding http://192.168.2.18:9090/home/json with 10000000 request(s) using 100
 connection(s)
 10000000 / 10000000 [============================================] 100.00% 54s
Done!
Statistics        Avg      Stdev        Max
  Reqs/sec    184345.82   24707.02  208438.54
  Latency      537.74us     1.07ms   395.02ms
  HTTP codes:
    1xx - 0, 2xx - 10000000, 3xx - 0, 4xx - 0, 5xx - 0
    others - 0
  Throughput:    34.64MB/s
D:\>bombardier.exe -c 100 -n 10000000 "http://192.168.2.18:9090/home/employee/3"

Bombarding http://192.168.2.18:9090/home/employee/3 with 10000000 request(s) usi
ng 100 connection(s)
 10000000 / 10000000 [==========================================] 100.00% 1m12s
Done!
Statistics        Avg      Stdev        Max
  Reqs/sec    138350.49   15090.09  162791.05
  Latency      717.80us     1.14ms   397.02ms
  HTTP codes:
    1xx - 0, 2xx - 10000000, 3xx - 0, 4xx - 0, 5xx - 0
    others - 0
  Throughput:    70.33MB/s
D:\>bombardier.exe -c 100 -n 10000000 "http://192.168.2.18:9090/home/orders/3?in
dex=0&size=5"
Bombarding http://192.168.2.18:9090/home/orders/3?index=0&size=5 with 10000000 r
equest(s) using 100 connection(s)
 10000000 / 10000000 [==========================================] 100.00% 2m26s
Done!
Statistics        Avg      Stdev        Max
  Reqs/sec     68505.91    3209.14   72597.10
  Latency        1.46ms     2.14ms   599.03ms
  HTTP codes:
    1xx - 0, 2xx - 10000000, 3xx - 0, 4xx - 0, 5xx - 0
    others - 0
  Throughput:   118.06MB/s
 

完全なテストコード


https://github.com/IKende/FastHttpApi/tree/master/PerformanceTest/Beetlex_VS_AspCore_webapi