This is an automated email from the ASF dual-hosted git repository.

lhotari pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/pulsar.git

commit e5515c5d17366087025e2a243a988a3290728515
Author: Lari Hotari <[email protected]>
AuthorDate: Wed May 8 06:56:35 2024 +0300

    [improve][ws] Add memory limit configuration for Pulsar client used in 
Websocket proxy (#22666)
    
    (cherry picked from commit 80d46758e89b088688d521aa8ae401bfb00c98b2)
---
 conf/broker.conf                                                   | 3 +++
 conf/standalone.conf                                               | 3 +++
 conf/websocket.conf                                                | 3 +++
 .../main/java/org/apache/pulsar/broker/ServiceConfiguration.java   | 7 +++++++
 .../main/java/org/apache/pulsar/websocket/WebSocketService.java    | 3 ++-
 .../pulsar/websocket/service/WebSocketProxyConfiguration.java      | 3 +++
 6 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/conf/broker.conf b/conf/broker.conf
index 34f7ab017e9..d5f10a487f2 100644
--- a/conf/broker.conf
+++ b/conf/broker.conf
@@ -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
 
diff --git a/conf/standalone.conf b/conf/standalone.conf
index a7d9990b7cc..ab0f2cebf66 100644
--- a/conf/standalone.conf
+++ b/conf/standalone.conf
@@ -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
 
diff --git a/conf/websocket.conf b/conf/websocket.conf
index 9051f3b590c..91f7f7d4c23 100644
--- a/conf/websocket.conf
+++ b/conf/websocket.conf
@@ -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
 
diff --git 
a/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/ServiceConfiguration.java
 
b/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/ServiceConfiguration.java
index 55c9771b901..ff33d9103ab 100644
--- 
a/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/ServiceConfiguration.java
+++ 
b/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/ServiceConfiguration.java
@@ -2836,6 +2836,13 @@ public class ServiceConfiguration implements 
PulsarConfiguration {
         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"
diff --git 
a/pulsar-websocket/src/main/java/org/apache/pulsar/websocket/WebSocketService.java
 
b/pulsar-websocket/src/main/java/org/apache/pulsar/websocket/WebSocketService.java
index 66b2a0075ec..889f4431cc3 100644
--- 
a/pulsar-websocket/src/main/java/org/apache/pulsar/websocket/WebSocketService.java
+++ 
b/pulsar-websocket/src/main/java/org/apache/pulsar/websocket/WebSocketService.java
@@ -195,7 +195,8 @@ public class WebSocketService implements Closeable {
 
     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()) //
diff --git 
a/pulsar-websocket/src/main/java/org/apache/pulsar/websocket/service/WebSocketProxyConfiguration.java
 
b/pulsar-websocket/src/main/java/org/apache/pulsar/websocket/service/WebSocketProxyConfiguration.java
index 3fcbcf4b215..31a1adc2915 100644
--- 
a/pulsar-websocket/src/main/java/org/apache/pulsar/websocket/service/WebSocketProxyConfiguration.java
+++ 
b/pulsar-websocket/src/main/java/org/apache/pulsar/websocket/service/WebSocketProxyConfiguration.java
@@ -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;
 

Reply via email to