Skip to content

Commit

Permalink
[improve][ws] Add memory limit configuration for Pulsar client used i…
Browse files Browse the repository at this point in the history
…n Websocket proxy (apache#22666)

(cherry picked from commit 80d4675)
  • Loading branch information
lhotari committed May 14, 2024
1 parent 34ce38e commit e5515c5
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions conf/broker.conf
Original file line number Diff line number Diff line change
Expand Up @@ -1535,6 +1535,9 @@ webSocketNumServiceThreads=
# Number of connections per Broker in Pulsar Client used in WebSocket proxy
webSocketConnectionsPerBroker=

# Memory limit in MBs for direct memory in Pulsar Client used in WebSocket proxy
webSocketPulsarClientMemoryLimitInMB=0

# Time in milliseconds that idle WebSocket session times out
webSocketSessionIdleTimeoutMillis=300000

Expand Down
3 changes: 3 additions & 0 deletions conf/standalone.conf
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,9 @@ webSocketNumIoThreads=8
# Number of connections per Broker in Pulsar Client used in WebSocket proxy
webSocketConnectionsPerBroker=8

# Memory limit in MBs for direct memory in Pulsar Client used in WebSocket proxy
webSocketPulsarClientMemoryLimitInMB=0

# Time in milliseconds that idle WebSocket session times out
webSocketSessionIdleTimeoutMillis=300000

Expand Down
3 changes: 3 additions & 0 deletions conf/websocket.conf
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ numHttpServerThreads=
# Number of connections per Broker in Pulsar Client used in WebSocket proxy
webSocketConnectionsPerBroker=

# Memory limit in MBs for direct memory in Pulsar Client used in WebSocket proxy
webSocketPulsarClientMemoryLimitInMB=0

# Time in milliseconds that idle WebSocket session times out
webSocketSessionIdleTimeoutMillis=300000

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2836,6 +2836,13 @@ The delayed message index time step(in seconds) in per bucket snapshot segment,
doc = "Number of connections per Broker in Pulsar Client used in WebSocket proxy"
)
private int webSocketConnectionsPerBroker = Runtime.getRuntime().availableProcessors();

@FieldContext(
category = CATEGORY_WEBSOCKET,
doc = "Memory limit in MBs for direct memory in Pulsar Client used in WebSocket proxy"
)
private int webSocketPulsarClientMemoryLimitInMB = 0;

@FieldContext(
category = CATEGORY_WEBSOCKET,
doc = "Time in milliseconds that idle WebSocket session times out"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ public synchronized void setLocalCluster(ClusterData clusterData) {

private PulsarClient createClientInstance(ClusterData clusterData) throws IOException {
ClientBuilder clientBuilder = PulsarClient.builder() //
.memoryLimit(0, SizeUnit.BYTES)
.memoryLimit(SizeUnit.MEGA_BYTES.toBytes(config.getWebSocketPulsarClientMemoryLimitInMB()),
SizeUnit.BYTES)
.statsInterval(0, TimeUnit.SECONDS) //
.enableTls(config.isTlsEnabled()) //
.allowTlsInsecureConnection(config.isTlsAllowInsecureConnection()) //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ public class WebSocketProxyConfiguration implements PulsarConfiguration {
@FieldContext(doc = "Number of connections per broker in Pulsar client used in WebSocket proxy")
private int webSocketConnectionsPerBroker = Runtime.getRuntime().availableProcessors();

@FieldContext(doc = "Memory limit in MBs for direct memory in Pulsar Client used in WebSocket proxy")
private int webSocketPulsarClientMemoryLimitInMB = 0;

@FieldContext(doc = "Timeout of idling WebSocket session (in milliseconds)")
private int webSocketSessionIdleTimeoutMillis = 300000;

Expand Down

0 comments on commit e5515c5

Please sign in to comment.