最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

.net core如何利用ConcurrentTest組件對(duì)方法進(jìn)行壓力測(cè)試詳解

 更新時(shí)間:2018年11月06日 10:01:38   作者:smark  
這篇文章主要給大家介紹了關(guān)于.net core如何利用ConcurrentTest組件對(duì)方法進(jìn)行壓力測(cè)試的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起看看吧

前言

工欲善其事,必先利其器!在編寫(xiě)服務(wù)中首先要有一個(gè)好的測(cè)試工具,在dontecore下性能測(cè)試有BenchmarkDotNet,只需要簡(jiǎn)單的配置一下就可以對(duì)方法的性能進(jìn)行詳細(xì)的測(cè)試。但有時(shí)候需要對(duì)不同并發(fā)下看其處理效率和延時(shí)統(tǒng)計(jì)查看,如HTTP服務(wù)對(duì)應(yīng)著大量的測(cè)試工具如ab,bombardier等等。由于找不到類(lèi)似于測(cè)試HTTP服務(wù)的工具來(lái)測(cè)試代碼用例,于時(shí)就有了ConcurrentTest這個(gè)組件的實(shí)現(xiàn).通過(guò)ConcurrentTest組件可以運(yùn)行不同的測(cè)試用例,并可以實(shí)時(shí)查看具體的并發(fā)情況和延時(shí)分布數(shù)據(jù)。

以下介紹一下如何使用ConcurrentTest運(yùn)行測(cè)試用例并統(tǒng)計(jì)運(yùn)行結(jié)果,話不多說(shuō)了,來(lái)一起看看詳細(xì)的介紹吧

引用組件

Install-Package BeetleX.ConcurrentTest -Version 0.2.8

WebAPI服務(wù)

[Route("api/[controller]")]
  [ApiController]
  public class EmployeeController : ControllerBase
  {
    [HttpGet("{count}")]
    public JsonResult Get(int count)
    {
      return new JsonResult(Employee.GetEmployees(count));
    }
    [HttpPost]
    public JsonResult Post([FromBody]Employee value)
    {
      return new JsonResult(value);
    }
  }

以上是一個(gè)簡(jiǎn)單的dotnet core WebApi服務(wù),主要是提供了雇員獲取和添加功能。

測(cè)試用例

public class FastHttpClientTest
  {
    public FastHttpClientTest()
    {
      httpApiClient = new HttpApiClient(Host);
      clientApi = httpApiClient.CreateWebapi<IHttpClientApi>();
    }
    private string Host = "http://localhost:8007";
    private BeetleX.FastHttpApi.HttpApiClient httpApiClient;
    private IHttpClientApi clientApi;
    [CTestCase]
    public void AddEmployee()
    {
      clientApi.AddEmployee(Employee.GetEmployee());
    }
    [CTestCase]
    public void ListEmployees()
    {
      clientApi.ListEmployees(2);
    }
    [JsonFormater]
    public interface IHttpClientApi
    {
      [Get(Route = "api/employee/{count}")]
      List<Employee> ListEmployees(int count);
      [Post(Route = "api/employee")]
      Employee AddEmployee(Employee item);
    }
  }

組件使用起來(lái)和BenchmarkDotNet差不多,通過(guò)CTestCase來(lái)標(biāo)記,具體測(cè)試方法通過(guò)接口定義。使用接口來(lái)描述WebApi請(qǐng)求是FastHttpApi,在這里就不過(guò)多說(shuō)明。

使用ConcurrentTest進(jìn)行壓力測(cè)試

當(dāng)測(cè)試用例編寫(xiě)完成后,就可以使用ConcurrentTest對(duì)測(cè)試用例進(jìn)行一個(gè)多線程并發(fā)測(cè)試;只需要簡(jiǎn)單運(yùn)行以下代碼即可

CTester.RunTest<FastHttpClientTest>(10, 500000);

以上代碼是對(duì)FastHttpClientTest的所有測(cè)試方法進(jìn)行一個(gè)測(cè)試,測(cè)試數(shù)據(jù)是使用10個(gè)線程,進(jìn)行500000萬(wàn)次調(diào)用測(cè)試。

測(cè)試報(bào)表

在運(yùn)行過(guò)程中組件會(huì)實(shí)時(shí)顯示并發(fā)情況和區(qū)間響應(yīng)數(shù)量,最終會(huì)針對(duì)每個(gè)測(cè)試用例形成一個(gè)簡(jiǎn)要的測(cè)試結(jié)果;具體結(jié)果如下:

***********************************************************************
* https://github.com/IKende/ConcurrentTest.git
* Copyright ? ikende.com 2018 email:henryfan@msn.com
* ServerGC:True
***********************************************************************
* AddEmployee test prepping completed
-----------------------------------------------------------------------
* [500000/500000]|threads:[10]
* Success:[ 0/s]|total:[ 500000][min:23448/s max:24561/s]
* Error:[ 0/s]|total:[ 0][min:0/s max:0/s]
-----------------------------------------------------------------------
* 0ms-0.1ms:[ ] 0.1ms-0.5ms:[ 435,604]
* 0.5ms-1ms:[ 59,863] 1ms-5ms:[ 4,356]
* 5ms-10ms:[ 142] 10ms-50ms:[ 35]
* 50ms-100ms:[ ] 100ms-1000ms:[ ]
* 1000ms-5000ms:[ ] 5000ms-10000ms:[ ]
***********************************************************************

***********************************************************************
* ListEmployees test prepping completed
-----------------------------------------------------------------------
* [500000/500000]|threads:[10]
* Success:[ 0/s]|total:[ 500000][min:28105/s max:28829/s]
* Error:[ 0/s]|total:[ 0][min:0/s max:0/s]
-----------------------------------------------------------------------
* 0ms-0.1ms:[ ] 0.1ms-0.5ms:[ 476,342]
* 0.5ms-1ms:[ 20,641] 1ms-5ms:[ 2,922]
* 5ms-10ms:[ 80] 10ms-50ms:[ 15]
* 50ms-100ms:[ ] 100ms-1000ms:[ ]
* 1000ms-5000ms:[ ] 5000ms-10000ms:[ ]
***********************************************************************

組件還具備什么功能

現(xiàn)有的ConcurrentTest的功能還相對(duì)簡(jiǎn)陋,不過(guò)應(yīng)用者還是可以根據(jù)實(shí)際的需要來(lái)制定統(tǒng)計(jì)標(biāo)簽,延時(shí)區(qū)間等相關(guān)統(tǒng)計(jì);由于組件的代碼也非常少只有幾個(gè)類(lèi),你也根據(jù)根據(jù)自己的需要來(lái)擴(kuò)展它或在https://github.com/IKende/ConcurrentTest提上相應(yīng)issues

總結(jié)

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,如果有疑問(wèn)大家可以留言交流,謝謝大家對(duì)腳本之家的支持。

相關(guān)文章

最新評(píng)論

保德县| 轮台县| 大庆市| 金门县| 渭源县| 扎囊县| 宣化县| 当阳市| 济源市| 新乐市| 临沧市| 河南省| 理塘县| 辛集市| 西吉县| 辰溪县| 阜新市| 门源| 普安县| 濮阳县| 交城县| 射阳县| 同德县| 鸡西市| 合山市| 巍山| 息烽县| 乌兰浩特市| 马鞍山市| 财经| 资溪县| 乳源| 辰溪县| 连南| 承德县| 赣榆县| 炉霍县| 左权县| 霸州市| 抚宁县| 乌苏市|