Skip to content

Commit 6637e13

Browse files
committed
Adding response duration sleep
1 parent 18c0058 commit 6637e13

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

src/main/java/com/emc/mongoose/storage/driver/coop/netty/NettyStorageDriverBase.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public abstract class NettyStorageDriverBase<I extends Item, O extends Operation
7474
private final Class<SocketChannel> socketChannelCls;
7575
private final NonBlockingConnPool connPool;
7676
private final boolean sslFlag;
77+
private final int responseDuration;
7778
private final SslContext sslCtx;
7879
protected final ChannelFutureListener reqSentCallback = this::sendFullRequestComplete;
7980

@@ -205,6 +206,7 @@ protected NettyStorageDriverBase(
205206
try (final var logCtx = CloseableThreadContext.put(KEY_STEP_ID, this.stepId).put(KEY_CLASS_NAME, CLS_NAME)) {
206207
connPool = createConnectionPool();
207208
}
209+
responseDuration = netConfig.intVal("response-duration");
208210
}
209211

210212
protected NonBlockingConnPool createConnectionPool() {
@@ -578,6 +580,13 @@ public void complete(final Channel channel, final O op) {
578580
ThreadContext.put(KEY_STEP_ID, stepId);
579581

580582
try {
583+
if (responseDuration > 0) {
584+
try {
585+
long elapsed = (op.START_OFFSET_MICROS + System.nanoTime() / 1000) - op.reqTimeStart();
586+
long sleepMs = responseDuration - (elapsed / 1000);
587+
if (sleepMs > 0) { Thread.sleep(sleepMs); }
588+
} catch (Exception e) {}
589+
}
581590
op.finishResponse();
582591
} catch (final IllegalStateException e) {
583592
LogUtil.exception(Level.DEBUG, e, "{}: invalid load operation state", op.toString());

src/main/resources/config-schema-storage-net.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ storage:
2424
port: int
2525
slice: boolean
2626
writeSpinCount: int
27+
response:
28+
duration: int

src/main/resources/config/defaults-storage-net.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ storage:
2828
port: 7
2929
slice: false
3030
writeSpinCount: 1
31+
response:
32+
duration: -1

0 commit comments

Comments
 (0)