Page History
...
- [PASS] Expected [Counter] TestCounter to must be greater than 1,000.00 operations; actual value was 94,160.06 operations.
- CounterThroughputAssertion 에서 설정된 값 이상인 최소 TPS 통과됨을 의미하며 추가로 94160 수행되었음을 표현합니다.
- [PASS] Expected [Counter] TestCounter to must be greater than 1,500.00 operations; actual value was 93,000.00 operations.
- CounterTotalAssertion 에서 설정된 값 이상인 평균 TPS가 통과됨을 의미하며 평균 수행횟수가 93000임을 표현합니다.
성능제약 테스트
...
다양한 이유로 호출량을 통제해야할 필요도 있습니다. 최종 소비자가 충분한 소비를 하지못하는경우 생산을 제약하는 경우이며
성능제약이 잘 작동하는지도 검증할수 있습니다.
이벤트가를 N개 동시 발생하며, 소비가 되는구간에서 성능카운트를 1올려줍니다.
| Code Block |
|---|
[Theory(DisplayName = "테스트 n초당 1회 호출제약")]
[InlineData(5, 1, false)]
public void ThrottleLimitTest(int givenTestCount, int givenLimitSeconds, bool isPerformTest)
{
.......
// Create ThrottleLimit Actor
throttleLimitActor = actorSystem.ActorOf(Props.Create(() => new ThrottleLimitActor(1, givenLimitSeconds, 1000)));
throttleLimitActor.Tell(new SetTarget(probe))
for (int i = 0; i < givenTestCount; i++)
{
throttleLimitActor.Tell(new EventCmd()
{
Message = "test",
});
}
//Then : Safe processing within N seconds limit
for (int i = 0; i < givenTestCount; i++)
{
probe.ExpectMsg<EventCmd>(message =>
{
Assert.Equal("test", message.Message);
});
output.WriteLine($"[{DateTime.Now}] - GTPRequestCmd");
if (isPerformTest)
{
_dictionary.Add(_key++, _key);
_addCounter.Increment();
}
}
...........
} |
도메인 검증은 발생메시지가 모두 소비되었나를 검증하며 , TPS 1을 유지하였는가 성능검증은 다음과같이 작성합니다.
| Code Block |
|---|
[NBenchFact]
[PerfBenchmark(NumberOfIterations = 3, RunMode = RunMode.Throughput,
RunTimeMilliseconds = 1000, TestMode = TestMode.Test)]
[CounterThroughputAssertion("TestCounter", MustBe.LessThanOrEqualTo, 1.0d)]
[CounterTotalAssertion("TestCounter", MustBe.LessThanOrEqualTo, 1)]
[CounterMeasurement("TestCounter")]
public void ThrottleLimitPerformanceTest()
{
ThrottleLimitTest(1, 1, true);
} |
통과옵션을을 1보다 작다로 설정을 하여 TPS1이하인지 검증을 할수가 있습니다.
- [CounterThroughputAssertion("TestCounter", MustBe.LessThanOrEqualTo, 1.0d)]
- [CounterTotalAssertion("TestCounter", MustBe.LessThanOrEqualTo, 1)]
성능제약 통과 로그
| Code Block |
|---|
[PASS] Expected [Counter] TestCounter to must be less than or equal to 1.00 operations; actual value was 0.98 operations.
[PASS] Expected [Counter] TestCounter to must be less than or equal to 1.00 operations; actual value was 1.00 operations.
---------- Measurements ----------
Metric : [Counter] TestCounter
Per Second ( operations )
Average : 0.9802234345891607
Max : 0.9823810933292493
Min : 0.9787775577268321
Std. Deviation : 0.0019042957466220024
Std. Error : 0.0010994456619288725
Per Test ( operations )
Average : 1
Max : 1
Min : 1
Std. Deviation : 0
Std. Error : 0
|
검증 옵션을 GreaterThanOrEqualTo 반대로 설정을 하면 실패가 발생하며 아래와같이 검증 실패가 발생하게됩니다.
| Code Block |
|---|
[FAIL] Expected [Counter] TestCounter to must be greater than or equal to 1.00 operations; actual value was 0.98 operations.
Expected: True
Actual: False |
샘플 코드 : https://github.com/psmon/NetCoreLabs/blob/main/ActorLibTest/tools/ThrottleLimitActorTest.cs
이상 유닛테스트와 함께 심플한 성능테스트를 함께 할수 있는 방법을 살펴보았으며
측정할수 없으면 개선할수 없으며~ 활용된 기술의 링크도 측정할수 없으면 개선할수 없으며 사용된 기술의 참고링크도 추가하였습니다.
참고링크 :
- https://getakka.net/articles/actors/testing-actor-systems.html
- https://nbench.io/
- https://github.com/Pro-Coded-External/Pro.NBench.xUnit
...