aboutsummaryrefslogtreecommitdiffstats
path: root/jdisc_http_service
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
parent36221bb67238256d46cb0fe69ca682172d2bec65 (diff)
Change memory threshold to a percentage of total memory
Diffstat (limited to 'jdisc_http_service')
-rw-r--r--jdisc_http_service/src/main/java/com/yahoo/jdisc/http/server/jetty/ConnectionThrottler.java14
-rw-r--r--jdisc_http_service/src/main/resources/configdefinitions/jdisc.http.connector.def4
-rw-r--r--jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpServerTest.java2
3 files changed, 12 insertions, 8 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());
diff --git a/jdisc_http_service/src/main/resources/configdefinitions/jdisc.http.connector.def b/jdisc_http_service/src/main/resources/configdefinitions/jdisc.http.connector.def
index ae4e66a236b..7967f657aff 100644
--- a/jdisc_http_service/src/main/resources/configdefinitions/jdisc.http.connector.def
+++ b/jdisc_http_service/src/main/resources/configdefinitions/jdisc.http.connector.def
@@ -47,8 +47,8 @@ throttling.enabled bool default=false
# Max number of connections.
throttling.maxConnections int default=-1
-# Max memory usage in megabytes (totalMemory - freeMemory).
-throttling.maxMemoryUsage int default=-1
+# Max memory utilization as a value between 0 and 1.
+throttling.maxHeapUtilization double default=-1
# Max connection accept rate.
throttling.maxAcceptRate int default=-1
diff --git a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpServerTest.java b/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpServerTest.java
index 479cf514e30..9622edc5429 100644
--- a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpServerTest.java
+++ b/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpServerTest.java
@@ -490,7 +490,7 @@ public class HttpServerTest {
.throttling(new Throttling.Builder()
.enabled(true)
.maxAcceptRate(10)
- .maxMemoryUsage(100*1024)
+ .maxHeapUtilization(0.99)
.maxConnections(10)));
driver.client().get("/status.html")
.expectStatusCode(is(OK));