Skip to content

Commit 9bf0901

Browse files
committed
SocketExecutor: Add getTotalPendingWriteBytes and getTotalPendingReadBytes
This metric helps you know across all clients how backed up you are either consuming data into the application (likely cpu or otherwise bound by the application), or write bound (network or remote side being the bottleneck).
1 parent 11653b4 commit 9bf0901

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/main/java/org/threadly/litesockets/SocketExecuter.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,23 @@ public interface SocketExecuter extends Service {
2929
*/
3030
public void setPerConnectionStatsEnabled(boolean enabled);
3131

32+
33+
/**
34+
* Check the total number of bytes pending to be sent by clients. This is data which has been
35+
* provided to the client to write, but is waiting on the network and kernel to accept the write.
36+
*
37+
* @return The total number of bytes pending to write by clients
38+
*/
39+
public long getTotalPendingWriteBytes();
40+
41+
/**
42+
* Check the total amount of pending reads across all associated clients. Bytes here indicate
43+
* that the client has been notified a read is available but has not consumed it.
44+
*
45+
* @return The total number of bytes pending to read by clients
46+
*/
47+
public long getTotalPendingReadBytes();
48+
3249
/**
3350
* This will create a UDPServer on the specified {@link SocketExecuter}.
3451
*

src/main/java/org/threadly/litesockets/SocketExecuterCommonBase.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,25 @@ abstract class SocketExecuterCommonBase extends AbstractService implements Socke
4747
this.acceptScheduler = acceptScheduler;
4848
}
4949

50+
@Override
51+
public long getTotalPendingWriteBytes() {
52+
long result = 0;
53+
for (Client c : clients.values()) {
54+
result += c.getWriteBufferSize();
55+
}
56+
return result;
57+
}
58+
59+
@Override
60+
public long getTotalPendingReadBytes() {
61+
long result = 0;
62+
for (Client c : clients.values()) {
63+
result += c.getReadBufferSize();
64+
}
65+
return result;
66+
}
67+
68+
@Override
5069
public void setPerConnectionStatsEnabled(boolean enabled) {
5170
perConnectionStatsEnabled = enabled;
5271
}

0 commit comments

Comments
 (0)