Skip to content

Commit

Permalink
⚡ Remove RequestLimitingHandler from base pipeline and linked request…
Browse files Browse the repository at this point in the history
…s-limit configuration option
  • Loading branch information
ujibang committed Feb 2, 2024
1 parent be7444e commit a9ea00e
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 48 deletions.
3 changes: 0 additions & 3 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -560,9 +560,6 @@ restHeartConfiguration:

## Limits

# Limit for the maximum number of concurrent requests being served
requests-limit: 1000

# Time limit in milliseconds for processing queries on the server (without network latency). 0 means no time limit
query-time-limit: 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,20 @@
*/
package org.restheart.configuration;

import static org.restheart.configuration.Utils.getOrDefault;
import static org.restheart.configuration.Utils.asMap;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import static org.restheart.configuration.Utils.asMap;
import static org.restheart.configuration.Utils.getOrDefault;

public record CoreModule(String name,
String pluginsDirectory,
List<String> pluginsPackages,
boolean pluginsScanningVerbose,
String baseUrl,
int ioThreads,
int workerThreads,
int requestsLimit,
int bufferSize,
boolean directBuffers,
boolean forceGzipEncoding,
Expand All @@ -47,13 +46,12 @@ public record CoreModule(String name,
public static final String BASE_URL_KEY = "base-url";
public static final String IO_THREADS_KEY = "io-threads";
public static final String WORKER_THREADS_KEY = "worker-threads";
public static final String REQUESTS_LIMIT_KEY = "requests-limit";
public static final String BUFFER_SIZE_KEY = "buffer-size";
public static final String DIRECT_BUFFERS_KEY = "direct-buffers";
public static final String FORCE_GZIP_ENCODING_KEY = "force-gzip-encoding";
public static final String ALLOW_UNESCAPED_CHARS_IN_ULR_KEY = "allow-unescaped-characters-in-url";

private static final CoreModule DEFAULT_CORE_MODULE = new CoreModule("default", "plugins", new ArrayList<>(), false, null, 0, -1, 1000, 16364, true, false, true);
private static final CoreModule DEFAULT_CORE_MODULE = new CoreModule("default", "plugins", new ArrayList<>(), false, null, 0, -1, 16364, true, false, true);

public CoreModule(Map<String, Object> conf, boolean silent) {
this(
Expand All @@ -65,14 +63,12 @@ public CoreModule(Map<String, Object> conf, boolean silent) {
getOrDefault(conf, BASE_URL_KEY, DEFAULT_CORE_MODULE.baseUrl(), true),
getOrDefault(conf, IO_THREADS_KEY, DEFAULT_CORE_MODULE.ioThreads(), silent),
getOrDefault(conf, WORKER_THREADS_KEY, DEFAULT_CORE_MODULE.workerThreads(), silent),
getOrDefault(conf, REQUESTS_LIMIT_KEY, DEFAULT_CORE_MODULE.requestsLimit(), silent),
getOrDefault(conf, BUFFER_SIZE_KEY, DEFAULT_CORE_MODULE.bufferSize(), silent),
getOrDefault(conf, DIRECT_BUFFERS_KEY, DEFAULT_CORE_MODULE.directBuffers(), silent),
// following is optional, so get it always in silent mode
getOrDefault(conf, FORCE_GZIP_ENCODING_KEY, DEFAULT_CORE_MODULE.forceGzipEncoding(), true),
// following is optional, so get it always in silent mode
getOrDefault(conf, ALLOW_UNESCAPED_CHARS_IN_ULR_KEY, DEFAULT_CORE_MODULE.allowUnescapedCharsInUrl(),
true));
getOrDefault(conf, ALLOW_UNESCAPED_CHARS_IN_ULR_KEY, DEFAULT_CORE_MODULE.allowUnescapedCharsInUrl(), true));
}

public static CoreModule build(Map<String, Object> conf, boolean silent) {
Expand Down
22 changes: 9 additions & 13 deletions core/src/main/java/org/restheart/Bootstrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@
import io.undertow.server.handlers.AllowedMethodsHandler;
import io.undertow.server.handlers.GracefulShutdownHandler;
import io.undertow.server.handlers.HttpContinueAcceptingHandler;
import io.undertow.server.handlers.RequestLimit;
import io.undertow.server.handlers.RequestLimitingHandler;
import io.undertow.server.handlers.proxy.LoadBalancingProxyClient;
import io.undertow.server.handlers.proxy.ProxyHandler;
import io.undertow.server.handlers.resource.FileResourceManager;
Expand Down Expand Up @@ -682,17 +680,15 @@ private static GracefulShutdownHandler getPipeline(final Set<PluginRecord<AuthMe
*/
private static GracefulShutdownHandler getBasePipeline() {
return new GracefulShutdownHandler(
new RequestLimitingHandler(
new RequestLimit(configuration.coreModule().requestsLimit()),
new AllowedMethodsHandler(
new ErrorHandler(PipelinedWrappingHandler.wrap(new HttpContinueAcceptingHandler(PluginsRegistryImpl.getInstance().getRootPathHandler()))),
// allowed methods
HttpString.tryFromString(ExchangeKeys.METHOD.GET.name()),
HttpString.tryFromString(ExchangeKeys.METHOD.POST.name()),
HttpString.tryFromString(ExchangeKeys.METHOD.PUT.name()),
HttpString.tryFromString(ExchangeKeys.METHOD.DELETE.name()),
HttpString.tryFromString(ExchangeKeys.METHOD.PATCH.name()),
HttpString.tryFromString(ExchangeKeys.METHOD.OPTIONS.name()))));
new AllowedMethodsHandler(
new ErrorHandler(PipelinedWrappingHandler.wrap(new HttpContinueAcceptingHandler(PluginsRegistryImpl.getInstance().getRootPathHandler()))),
// allowed methods
HttpString.tryFromString(ExchangeKeys.METHOD.GET.name()),
HttpString.tryFromString(ExchangeKeys.METHOD.POST.name()),
HttpString.tryFromString(ExchangeKeys.METHOD.PUT.name()),
HttpString.tryFromString(ExchangeKeys.METHOD.DELETE.name()),
HttpString.tryFromString(ExchangeKeys.METHOD.PATCH.name()),
HttpString.tryFromString(ExchangeKeys.METHOD.OPTIONS.name())));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,6 @@ core:
# if < 0, use the number of cores * 8. With 0 working threads, blocking services won't work.
worker-threads: -1

# Limit for the maximum number of concurrent requests being served
requests-limit: 1000

# Use 16k buffers for best performance - as in linux 16k is generally the default amount of data that can be sent in a single write() call
# Setting to 1024 * 16 - 20; the 20 is to allow some space for getProtocol headers, see UNDERTOW-1209
buffer-size: 16364
Expand Down
3 changes: 0 additions & 3 deletions core/src/main/resources/restheart-default-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,6 @@ core:
# if < 0, use the number of cores * 8. With 0 working threads, blocking services won't work.
worker-threads: -1

# Limit for the maximum number of concurrent requests being served
requests-limit: 1000

# Use 16k buffers for best performance - as in linux 16k is generally the default amount of data that can be sent in a single write() call
# Setting to 1024 * 16 - 20; the 20 is to allow some space for getProtocol headers, see UNDERTOW-1209
buffer-size: 16364
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
import static org.restheart.mongodb.MongoServiceConfigurationKeys.MONGO_URI_KEY;
import static org.restheart.mongodb.MongoServiceConfigurationKeys.QUERY_TIME_LIMIT_KEY;
import static org.restheart.mongodb.MongoServiceConfigurationKeys.REPRESENTATION_FORMAT_KEY;
import static org.restheart.mongodb.MongoServiceConfigurationKeys.REQUESTS_LIMIT_KEY;
import static org.restheart.mongodb.MongoServiceConfigurationKeys.SCHEMA_CACHE_ENABLED_KEY;
import static org.restheart.mongodb.MongoServiceConfigurationKeys.SCHEMA_CACHE_TTL_KEY;
import org.slf4j.Logger;
Expand Down Expand Up @@ -107,7 +106,6 @@ public class MongoServiceConfiguration {
private final long localCacheTtl;
private final boolean schemaCacheEnabled;
private final long schemaCacheTtl;
private final int requestsLimit;
private final boolean getCollectionCacheEnabled;
private final int getCollectionCacheSize;
private final int getCollectionCacheTTL;
Expand Down Expand Up @@ -204,8 +202,6 @@ private MongoServiceConfiguration(Map<String, Object> conf, boolean silent) thro

mongoMounts = asListOfMaps(conf, MONGO_MOUNTS_KEY, mongoMountsDefault, silent);

requestsLimit = asInteger(conf, REQUESTS_LIMIT_KEY, 100, silent);

queryTimeLimit = asLong(conf, QUERY_TIME_LIMIT_KEY, (long) 0, silent);
aggregationTimeLimit = asLong(conf, AGGREGATION_TIME_LIMIT_KEY, (long) 0, silent);
aggregationCheckOperators = asBoolean(conf, AGGREGATION_CHECK_OPERATORS, true, silent);
Expand Down Expand Up @@ -297,7 +293,7 @@ public String toString() {
+ ", defaultRepresentationFromat=" + defaultRepresentationFormat + ", mongoUri=" + mongoUri
+ ", mongoMounts=" + mongoMounts + ", localCacheEnabled="
+ localCacheEnabled + ", localCacheTtl=" + localCacheTtl + ", schemaCacheEnabled=" + schemaCacheEnabled
+ ", schemaCacheTtl=" + schemaCacheTtl + ", requestsLimit=" + requestsLimit
+ ", schemaCacheTtl=" + schemaCacheTtl
+ ", cacheEnabled=" + getCollectionCacheEnabled + ", cacheSize=" + getCollectionCacheSize + ", cacheTTL" + getCollectionCacheTTL
+ ", dbEtagCheckPolicy=" + dbEtagCheckPolicy + ", collEtagCheckPolicy=" + collEtagCheckPolicy + ", docEtagCheckPolicy="
+ docEtagCheckPolicy + ", connectionOptions=" + connectionOptions + ", queryTimeLimit=" + queryTimeLimit
Expand Down Expand Up @@ -333,13 +329,6 @@ public long getLocalCacheTtl() {
return localCacheTtl;
}

/**
* @return the requestsLimit
*/
public int getRequestsLimit() {
return requestsLimit;
}

/**
* @return the queryTimeLimit
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,6 @@ public interface MongoServiceConfigurationKeys {
*/
public static final String SCHEMA_CACHE_TTL_KEY = "schema-cache-ttl";

/**
* the key for the requests-limit property.
*/
public static final String REQUESTS_LIMIT_KEY = "requests-limit";

/**
* the key for the query-time-limit property.
*/
Expand Down

0 comments on commit a9ea00e

Please sign in to comment.