aboutsummaryrefslogtreecommitdiffstats
path: root/jdisc_http_service/src/main/java/com/yahoo/jdisc/http/server/jetty/ConnectionThrottler.java
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@oath.com>2018-12-10 13:57:59 +0100
committerBjørn Christian Seime <bjorncs@oath.com>2018-12-10 14:04:59 +0100
commit2db810113ffc50b26cae63c034cdf0f33b859c64 (patch)
tree961e937d17ec40362498ceda51358761b4d08bcc /jdisc_http_service/src/main/java/com/yahoo/jdisc/http/server/jetty/ConnectionThrottler.java
parent36221bb67238256d46cb0fe69ca682172d2bec65 (diff)
Change memory threshold to a percentage of total memory
Diffstat (limited to 'jdisc_http_service/src/main/java/com/yahoo/jdisc/http/server/jetty/ConnectionThrottler.java')
-rw-r--r--jdisc_http_service/src/main/java/com/yahoo/jdisc/http/server/jetty/ConnectionThrottler.java14
1 files changed, 9 insertions, 5 deletions
diff --git a/jdisc_http_service/src/main/java/com/yahoo/jdisc/http/server/jetty/ConnectionThrottler.java b/jdisc_http_service/src/main/java/com/yahoo/jdisc/http/server/jetty/ConnectionThrottler.java
index 370ac0aa788..79a4f93d1df 100644
--- a/jdisc_http_service/src/main/java/com/yahoo/jdisc/http/server/jetty/ConnectionThrottler.java
+++ b/jdisc_http_service/src/main/java/com/yahoo/jdisc/http/server/jetty/ConnectionThrottler.java
@@ -40,8 +40,8 @@ class ConnectionThrottler {
if (config.maxConnections() != -1) {
beans.add(new CoordinatedConnectionLimit(config.maxConnections(), idleTimeout));
}
- if (config.maxMemoryUsage() != -1) {
- beans.add(new CoordinatedLowResourcesLimit(config.maxMemoryUsage(), idleTimeout));
+ if (config.maxHeapUtilization() != -1) {
+ beans.add(new CoordinatedLowResourcesLimit(config.maxHeapUtilization(), idleTimeout));
}
}
@@ -70,12 +70,16 @@ class ConnectionThrottler {
}
resetters.forEach(Runnable::run);
}
+ private static long toMaxMemoryUsageInBytes(double maxHeapUtilization) {
+ return (long) (maxHeapUtilization * Runtime.getRuntime().maxMemory());
+ }
private class CoordinatedLowResourcesLimit extends LowResourceMonitor {
- CoordinatedLowResourcesLimit(int maxMemoryUsageMegaBytes, Duration idleTimeout) {
+
+ CoordinatedLowResourcesLimit(double maxHeapUtilization, Duration idleTimeout) {
super(connector.getServer());
super.setMonitoredConnectors(singleton(connector));
- super.setMaxMemory(maxMemoryUsageMegaBytes * 1024 * 1024L);
+ super.setMaxMemory(toMaxMemoryUsageInBytes(maxHeapUtilization));
super.setLowResourcesIdleTimeout((int)idleTimeout.toMillis());
}
@@ -90,8 +94,8 @@ class ConnectionThrottler {
ConnectionThrottler.this.onReset();
}
}
-
private class CoordinatedConnectionLimit extends ConnectionLimit {
+
CoordinatedConnectionLimit(int maxConnections, Duration idleTimeout) {
super(maxConnections, connector);
super.setIdleTimeout(idleTimeout.toMillis());