2017-01-20 19 views
1

私は10K + req/secを処理できるWeb APIアプリケーションを作成しようとしています。.NET Core Web APIのパフォーマンスを向上させる方法は?

私は空の.NET Core Web APIプロジェクトを作成しました.GETアクションが1つのみで、文字列を返すだけです。自己完結型のアプリケーションをDebian8サーバに公開します。

dotnet publish -r debian.8-x64 -c Release 

次に、次のオプションを使用してApache Benchmarkを使用して負荷テストを実行します。

ab -n 50000 -c -k 200 localhost:5000/api/cnt/dummy 

結果は4.5K req/secです。

私のWeb APIアプリケーションのパフォーマンスを向上させる方法はありますか?マイproject.jsonファイル

{ 
    "dependencies": { 
    "Microsoft.NETCore.App": { 
     "version": "1.0.1" 
    }, 
    "Microsoft.ApplicationInsights.AspNetCore": "1.0.0", 
    "Microsoft.AspNetCore.Mvc": "1.0.1", 
    "Microsoft.AspNetCore.Routing": "1.0.1", 
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0", 
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.1", 
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0", 
    "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0", 
    "Microsoft.Extensions.Configuration.Json": "1.0.0", 
    "Microsoft.Extensions.Logging": "1.0.0", 
    "Microsoft.Extensions.Logging.Console": "1.0.0", 
    "Microsoft.Extensions.Logging.Debug": "1.0.0", 
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0", 
    "Microsoft.AspNetCore.ResponseCompression": "1.0.0" 

    }, 

    "tools": { 
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final" 
    }, 

    "frameworks": { 
    "netcoreapp1.1": { 
     "imports": [ 
     "dnxcore50", 
     "portable-net45+win8" 
     ] 
    } 
    }, 

    "buildOptions": { 
    "emitEntryPoint": true, 
    "preserveCompilationContext": true 
    }, 

    "runtimeOptions": { 
    "configProperties": { 
     "System.GC.Server": true, 
     "System.GC.Concurrent": true 
    } 
    }, 

    "runtimes": { 
    "win10-x64": {}, 
    "debian.8-x64": {} 
    }, 

    "publishOptions": { 
    "include": [ 
     "wwwroot", 
     "**/*.cshtml", 
     "appsettings.json", 
     "web.config" 
    ] 
    }, 

    "scripts": { 
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ] 
    } 
} 

マイStartup.csファイル:

public class Startup 
{ 
    public Startup(IHostingEnvironment env) 
    { 
     var builder = new ConfigurationBuilder() 
      .SetBasePath(env.ContentRootPath) 
      .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) 
      .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true); 

     if (env.IsEnvironment("Development")) 
     { 
      // This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately. 
      builder.AddApplicationInsightsSettings(developerMode: true); 
     } 

     builder.AddEnvironmentVariables(); 
     Configuration = builder.Build(); 
    } 

    public IConfigurationRoot Configuration { get; } 

    // This method gets called by the runtime. Use this method to add services to the container 
    public void ConfigureServices(IServiceCollection services) 
    { 
     // Add framework services. 
     services.AddApplicationInsightsTelemetry(Configuration); 

     services.AddMvc(); 
    } 

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline 
    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) 
    { 
     loggerFactory.AddConsole(Configuration.GetSection("Logging")); 
     loggerFactory.AddDebug(); 

     app.UseApplicationInsightsRequestTelemetry(); 

     app.UseApplicationInsightsExceptionTelemetry(); 

     app.UseMvc(); 
    } 
} 
+5

こちらをご覧くださいhttps://github.com/aspnet/benchmarks。ベンチマークの実行を提供されている.NETのものと比較すると、コードやハードウェアに問題があるかどうかがわかります。あなたのマシンの仕様は何ですか?CPU使用率は? – CountZero

+0

Profilerを使用してアプリケーションのパフォーマンスをまだ理解しようとしましたか? Visual Studio Profilerを使用して、ほとんどの作業を行っていることを調べ、その知識を使用してアプリケーションのパフォーマンスを向上させることができます。 – PhillipH

+0

初心者として、MVCが必要かどうかを質問してください。本当に高いスループットは、ミドルウェアで直接行うのが最善です。ロギングとインサイトコスト。また、スレッドコントローラが原因でカウンタが誤ってカウントされる可能性があります。 – Thomas

答えて

1

経験abからは、あなたがこの番号をヒットさせません。 https://github.com/wg/wrkのような別の負荷テストツールが必要です。他の人たちもうまくいくでしょう。

複数のabプロセスを同時に使用できます。その後、特定の時間に特定の数のクライアントを使用します。たとえば、-c 20 -t 30 -kです。

関連する問題