Page History
닷넷코어 닷넷 환경에서 비동기적으로 작동하는 이벤트의 성능과 함께유닛테스트기를 활용하여 측정하고 검증할수 있는 방법을 Message Delivery Once 를 검증하는방법과
Nbench를 이용하여 유닛테스트환경에서 성능측정을 할수 있는방법을 소개합니다.
이 샘플에서는 액터메시지 모델이 이용되었지만 액터모델과 상관없이~ 유닛테스트내에서 심플한 방식으로 성능측정 기능을
유닛테스트내에서 성능측정 기법을 이용할수 있습니다.
측정할 수 없는 것은 관리할수 없다 - 피터 드러크
| Table of Contents |
|---|
테스트 탐색기
...
테스트 탐색기를 통해 성능유닛 테스트를 수행하고 측정할수 있습니다.
...
성능제약이 잘 작동하는지도 검증할수 있습니다.
이벤트가를 이벤트는 N개 동시 발생하며, 소비가 되는구간에서 성능카운트를 1올려줍니다.발생시킬수 있지만, TPS제약을 할수있는 ThrottleLimitActor 가 준비되었으며
| 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();
}
}
...........
} |
...
샘플 코드 : https://github.com/psmon/NetCoreLabs/blob/main/ActorLibTest/tools/ThrottleLimitActorTest.cs
이상 유닛테스트와 함께 심플한 성능테스트를 함께 할수 있는 방법을 살펴보았으며
여기서 확장된 개념이 소비자의 소비능력을 측정하여 생산량을 동적 TPS조절할수 있는 조절기를 설계하는것이 BackPressure 입니다.
GC 성능 테스트기
...
| Code Block |
|---|
---------- Measurements ----------
Metric : TotalCollections [Gen0]
Per Second ( collections )
Average : 251.73166139361632
Max : 305.97882626522244
Min : 178.82369771642138
Std. Deviation : 47.515272144026895
Std. Error : 15.025648361787713
Per Test ( collections )
Average : 1
Max : 1
Min : 1
Std. Deviation : 0
Std. Error : 0
----------
Metric : TotalCollections [Gen1]
Per Second ( collections )
Average : 251.73166139361632
Max : 305.97882626522244
Min : 178.82369771642138
Std. Deviation : 47.515272144026895
Std. Error : 15.025648361787713
Per Test ( collections )
Average : 1
Max : 1
Min : 1
Std. Deviation : 0
Std. Error : 0
|
GC 성능테스트 측정도 이용할수 있는것은 보너스입니다.
이상 유닛테스트와 함께 심플한 성능테스트를 함께 할수 있는 방법을 살펴보았으며
측정할 수 없으면 성능 개선을 할수 없는것과 마찬가지로 여기서 이용된 기술과 관련기술 링크도 첨부합니다.
JUnit with Bench
자바에서는 JHM를 이용하여 마이크로 벤치마크할수 있으며 대응하는 버전도 동일하게 준비되어있습니다.
링크 : https://github.com/psmon/java-labs/blob/master/springweb/src/jmh/java/com/webnori/springweb/akka/README.md측정할수 없으면 개선할수 없으며~ 활용된 기술의 링크도 추가하였습니다.
참고링크 :
- https://getakka.net/articles/actors/testing-actor-systems.html
- https://nbench.io/
- https://github.com/Pro-Coded-External/Pro.NBench.xUnit
- Introducing NBench - Automated Performance Testing and Benchmarking for .NET
- https://blog.knoldus.com/backpressure-in-akka-stream/
- https://www.baeldung.com/java-microbenchmark-harness
