728x90
Backpressure 관련 연산자
- delaySequence / limitRate
- sample
delaySequence
주어진 duration 만큼 지연시킵니다.
limitRate()
backpressure에 request를 조절하는 기능입니다.
limitRate()에서 적힌 수 많은 request를 강제합니다. 즉 request를 2번만 요청할 수 있습니다.
TestCode
public class Operator4 {
// limit
public Flux<Integer> fluxDelayAndLimit(){
return Flux.range(1,10)
.delaySequence(Duration.ofSeconds(1))
.log()
.limitRate(2);
}
}
class Operator4Test {
private Operator4 operator4 = new Operator4();
@Test
void fluxDelayAndLimit() {
StepVerifier.create(operator4.fluxDelayAndLimit())
.expectNext(1,2,3,4,5,6,7,8,9,10)
.verifyComplete();
}
}
sample
선별적으로 데이터를 Sampling합니다.
TestCode
public class Operator4 {
// sample
public Flux<Integer> fluxSample(){
return Flux.range(1,100)
.delayElements(Duration.ofMillis(100))
.sample(Duration.ofMillis(300))
.log();
}
}
class Operator4Test {
private Operator4 operator4 = new Operator4();
@Test
void fluxSample() {
StepVerifier.create(operator4.fluxSample())
.expectNextCount(1000)
.verifyComplete();
}
}
왼쪽의 테스트 결과를 보면 숫자가 순차적으로 나오긴 하지만, 사이사이가 비어있는것을 확인할 수 있습니다.
이는 sampling을 통해 데이터를 선별적으로 전달받을 수 있음을 의미합니다.
728x90
'SpringWebflux' 카테고리의 다른 글
[SpringWebflux] Reactor operator - 3 (0) | 2024.03.08 |
---|---|
[Spring Webflux] CPU bound vs I/O Bound (1) | 2024.03.07 |
[SpringWebflux] Spring Webflux 소개 (0) | 2024.03.06 |
[Spring Webflux] 스프링 웹플럭스(MVC와 비교, 내부 동작 원리, Netty) (0) | 2024.01.31 |
[Netty] @Sharable 어노테이션과 ChannelHandler 인스턴스 관리 (0) | 2024.01.10 |