成人无码视频,亚洲精品久久久久av无码,午夜精品久久久久久毛片,亚洲 中文字幕 日韩 无码

資訊專(zhuān)欄INFORMATION COLUMN

ContiPerf:: 更為優(yōu)雅和方便的單元壓力測(cè)試工具。

_Zhao / 3641人閱讀

摘要:概述是一個(gè)輕量級(jí)的單元測(cè)試工具,基于二次開(kāi)發(fā),使用它基于注解的方式,快速在本地進(jìn)行單元壓測(cè)并提供詳細(xì)的報(bào)告。當(dāng)和都有指定時(shí),以執(zhí)行次數(shù)多的為準(zhǔn)。測(cè)試報(bào)告最終的測(cè)試報(bào)告位于,使用瀏覽器打開(kāi)即可。

概述

ContiPerf 是一個(gè)輕量級(jí)的單元測(cè)試工具,基于JUnit 4二次開(kāi)發(fā),使用它基于注解的方式,快速在本地進(jìn)行單元壓測(cè)并提供詳細(xì)的報(bào)告。

Example 1. 新建 SpringBoot 工程
核心依賴(lài)如下

    org.springframework.boot
    spring-boot-starter-test
    test


    org.databene
    contiperf
    2.1.0
    test
2. 測(cè)試接口以及實(shí)現(xiàn)
package com.wuwenze.contiperf.service;

import java.util.List;

public interface ContiperfExampleService {

    List findAll();
}
import com.wuwenze.contiperf.service.ContiperfExampleService;

import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service
public class ContiperfExampleServiceImpl implements ContiperfExampleService {
    private final Random RANDOM = new Random();

    @Override
    public List findAll() {
        try {
            int sleepSecond = RANDOM.nextInt(10);
            log.info("#findAll(): sleep {} seconds..", sleepSecond);
            Thread.sleep(sleepSecond * 1000);
        } catch (InterruptedException e) {
            // ignore
        }
        List resultList = new ArrayList<>();
        for (int i = 0; i < 1000; i++) {
            resultList.add("string_" + i);
        }
        return resultList;
    }
}
3. 構(gòu)建單元測(cè)試
package com.wuwenze.contiperf.service;

import com.wuwenze.contiperf.ContiperfExamplesApplication;

import org.databene.contiperf.PerfTest;
import org.databene.contiperf.junit.ContiPerfRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;


@RunWith(SpringRunner.class)
@SpringBootTest(classes = ContiperfExamplesApplication.class)
public class ContiperfExampleServiceTest {
    @Rule
    public ContiPerfRule i = new ContiPerfRule();

    @Autowired
    private ContiperfExampleService contiperfExampleService;

    @Test
    @PerfTest(threads = 1000, duration = 1500)
    public void findAll() {
        contiperfExampleService
                .findAll()
                .forEach(System.out::println);
    }
}
4. 最終執(zhí)行效果

查看測(cè)試報(bào)告:

總結(jié) 1)PerfTest參數(shù)

@PerfTest(invocations = 300):執(zhí)行300次,和線程數(shù)量無(wú)關(guān),默認(rèn)值為1,表示執(zhí)行1次;
@PerfTest(threads=30):并發(fā)執(zhí)行30個(gè)線程,默認(rèn)值為1個(gè)線程;
@PerfTest(duration = 20000):重復(fù)地執(zhí)行測(cè)試至少執(zhí)行20s。
三個(gè)屬性可以組合使用,其中Threads必須和其他兩個(gè)屬性組合才能生效。當(dāng)Invocations和Duration都有指定時(shí),以執(zhí)行次數(shù)多的為準(zhǔn)。

  例,@PerfTest(invocations = 300, threads = 2, duration = 100),如果執(zhí)行方法300次的時(shí)候執(zhí)行時(shí)間還沒(méi)到100ms,則繼續(xù)執(zhí)行到滿足執(zhí)行時(shí)間等于100ms,如果執(zhí)行到50次的時(shí)候已經(jīng)100ms了,則會(huì)繼續(xù)執(zhí)行之100次。

  如果你不想讓測(cè)試連續(xù)不間斷的跑完,可以通過(guò)注釋設(shè)置等待時(shí)間,例,@PerfTest(invocations = 1000, threads = 10, timer = RandomTimer.class, timerParams = { 30, 80 }) ,每執(zhí)行完一次會(huì)等待30~80ms然后才會(huì)執(zhí)行下一次調(diào)用。

  在開(kāi)多線程進(jìn)行并發(fā)壓測(cè)的時(shí)候,如果一下子達(dá)到最大進(jìn)程數(shù)有些系統(tǒng)可能會(huì)受不了,ContiPerf還提供了“預(yù)熱”功能,例,@PerfTest(threads = 10, duration = 60000, rampUp = 1000) ,啟動(dòng)時(shí)會(huì)先起一個(gè)線程,然后每個(gè)1000ms起一線程,到9000ms時(shí)10個(gè)線程同時(shí)執(zhí)行,那么這個(gè)測(cè)試實(shí)際執(zhí)行了69s,如果只想衡量全力壓測(cè)的結(jié)果,那么可以在注釋中加入warmUp,即@PerfTest(threads = 10, duration = 60000, rampUp = 1000, warmUp = 9000) ,那么統(tǒng)計(jì)結(jié)果的時(shí)候會(huì)去掉預(yù)熱的9s。

2)Required參數(shù)

@Required(throughput = 20):要求每秒至少執(zhí)行20個(gè)測(cè)試;
@Required(average = 50):要求平均執(zhí)行時(shí)間不超過(guò)50ms;
@Required(median = 45):要求所有執(zhí)行的50%不超過(guò)45ms;
@Required(max = 2000):要求沒(méi)有測(cè)試超過(guò)2s;
@Required(totalTime = 5000):要求總的執(zhí)行時(shí)間不超過(guò)5s;
@Required(percentile90 = 3000):要求90%的測(cè)試不超過(guò)3s;
@Required(percentile95 = 5000):要求95%的測(cè)試不超過(guò)5s;
@Required(percentile99 = 10000):要求99%的測(cè)試不超過(guò)10s;
@Required(percentiles = "66:200,96:500"):要求66%的測(cè)試不超過(guò)200ms,96%的測(cè)試不超過(guò)500ms。

3)測(cè)試報(bào)告

最終的測(cè)試報(bào)告位于target/contiperf-report/index.html,使用瀏覽器打開(kāi)即可。

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://m.hztianpu.com/yun/76446.html

相關(guān)文章

  • ApiBoot DataSource Switch 使用文檔

    摘要:顧名思義,是用于數(shù)據(jù)源選擇切換的框架,這是一款基于切面指定注解實(shí)現(xiàn)的,通過(guò)簡(jiǎn)單的數(shù)據(jù)源注解配置就可以完成訪問(wèn)時(shí)的自動(dòng)切換,切換過(guò)程中是線程安全的。注意事項(xiàng)在使用時(shí)需要添加對(duì)應(yīng)數(shù)據(jù)庫(kù)的依賴(lài)如果使用連接池,不要配置使用的依賴(lài),請(qǐng)使用依賴(lài)。 ApiBoot是一款基于SpringBoot1.x,2.x的接口服務(wù)集成基礎(chǔ)框架, 內(nèi)部提供了框架的封裝集成、使用擴(kuò)展、自動(dòng)化完成配置,...

    AdolphLWQ 評(píng)論0 收藏0
  • 《Java應(yīng)用架構(gòu)設(shè)計(jì):模塊化模式與OSGi》讀書(shū)筆記

    摘要:本書(shū)概括以軟件系統(tǒng)為例,重點(diǎn)講解了應(yīng)用架構(gòu)中的物理設(shè)計(jì)問(wèn)題,即如何將軟件系統(tǒng)拆分為模塊化系統(tǒng)。容器獨(dú)立模塊不依賴(lài)于具體容器,采用輕量級(jí)容器,如獨(dú)立部署模塊可獨(dú)立部署可用性模式發(fā)布接口暴露外部配置使用獨(dú)立的配置文件用于不同的上下文。 本文為讀書(shū)筆記,對(duì)書(shū)中內(nèi)容進(jìn)行重點(diǎn)概括,并將書(shū)中的模塊化結(jié)合微服務(wù)、Java9 Jigsaw談?wù)劺斫狻?本書(shū)概括 以Java軟件系統(tǒng)為例,重點(diǎn)講解了應(yīng)用架構(gòu)...

    seanHai 評(píng)論0 收藏0
  • PHP相關(guān)

    摘要:的機(jī)器學(xué)習(xí)庫(kù)的機(jī)器學(xué)習(xí)庫(kù),包括算法交叉驗(yàn)證神經(jīng)網(wǎng)絡(luò)等內(nèi)容。在即將到來(lái)的大會(huì)上,她將和大家分享在機(jī)器學(xué)習(xí)領(lǐng)域的全新可能。入門(mén)總結(jié)入門(mén)相關(guān),如安裝配置基本使用等。 基于 Swoole 開(kāi)發(fā) PHP 擴(kuò)展 Swoole-1.9.7 增加了一個(gè)新特性,可以基于 Swoole 使用 C++ 語(yǔ)言開(kāi)發(fā)擴(kuò)展模塊,在擴(kuò)展模塊中可以注冊(cè) PHP 內(nèi)置函數(shù)和類(lèi)?,F(xiàn)在可以基于 Swoole 來(lái)編寫(xiě) PHP ...

    lewinlee 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

閱讀需要支付1元查看
<