Skip to content

Commit

Permalink
⚰️ Remove worker-threads configuration option since RESTHeart now use…
Browse files Browse the repository at this point in the history
…s Virtual Threads
  • Loading branch information
ujibang committed Apr 17, 2024
1 parent 9e3d1c1 commit 1ec4ec0
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ private static Map<String, Object> overrideConfiguration(Map<String, Object> con
overrides.stream().forEachOrdered(o -> {
if (!silent) {
if (o.value() instanceof HashMap<?, ?> mapValue) {
var maskedValue = new HashMap<>();
var maskedValue = new HashMap<String, Object>();
mapValue.keySet().stream()
.filter(k -> k instanceof String)
.map(k -> (String) k)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import java.util.List;
import java.util.Map;

import org.restheart.graal.ImageInfo;

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

Expand All @@ -34,7 +32,6 @@ public record CoreModule(String name,
boolean pluginsScanningVerbose,
String baseUrl,
int ioThreads,
int workerThreads,
int bufferSize,
boolean directBuffers,
boolean forceGzipEncoding,
Expand All @@ -47,13 +44,12 @@ public record CoreModule(String name,
public static final String PLUGINS_SCANNING_VERBOSE_KEY = "plugins-scanning-verbose";
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 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, 0, 16364, true, false, true);
private static final CoreModule DEFAULT_CORE_MODULE = new CoreModule("default", "plugins", new ArrayList<>(), false, null, 0, 16364, true, false, true);

public CoreModule(Map<String, Object> conf, boolean silent) {
this(
Expand All @@ -64,7 +60,6 @@ public CoreModule(Map<String, Object> conf, boolean silent) {
getOrDefault(conf, PLUGINS_SCANNING_VERBOSE_KEY, false, true),
getOrDefault(conf, BASE_URL_KEY, DEFAULT_CORE_MODULE.baseUrl(), true),
getOrDefault(conf, IO_THREADS_KEY, DEFAULT_CORE_MODULE.ioThreads(), silent),
workerThreads(conf),
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
Expand All @@ -73,19 +68,6 @@ public CoreModule(Map<String, Object> conf, boolean silent) {
getOrDefault(conf, ALLOW_UNESCAPED_CHARS_IN_ULR_KEY, DEFAULT_CORE_MODULE.allowUnescapedCharsInUrl(), true));
}

/**
* native image doesn't support Virtual Threads
* so workerThreads cannot be 0
* @param conf
*/
private static int workerThreads(Map<String, Object> conf) {
int workerThreads = getOrDefault(conf, WORKER_THREADS_KEY, DEFAULT_CORE_MODULE.workerThreads(), true);

return workerThreads == 0 && ImageInfo.inImageCode()
? -1 // this is autodetect
: workerThreads;
}

public static CoreModule build(Map<String, Object> conf, boolean silent) {
var core = asMap(conf, CORE_KEY, null, silent);

Expand Down
7 changes: 2 additions & 5 deletions core/src/main/java/org/restheart/Bootstrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -577,14 +577,11 @@ private static void startCoreSystem() {
var autoConfigIoThreads = configuration.coreModule().ioThreads() <= 0;
var ioThreads = autoConfigIoThreads ? Runtime.getRuntime().availableProcessors() : configuration.coreModule().ioThreads();

var autoConfigWorkerThreads = configuration.coreModule().workerThreads() < 0;
var workerThreads = autoConfigWorkerThreads ? Runtime.getRuntime().availableProcessors()*8 : configuration.coreModule().workerThreads();

LOGGER.info("Available processors: {}, IO threads{}: {}, worker threads{}: {}, ", Runtime.getRuntime().availableProcessors(), autoConfigIoThreads ? " (auto detected)" : "", ioThreads, autoConfigWorkerThreads ? " (auto detected)" : "", workerThreads);
LOGGER.info("Available processors: {}, IO threads{}: {}, worker virtual threads: \u221e", Runtime.getRuntime().availableProcessors(), autoConfigIoThreads ? " (auto detected)" : "", ioThreads);

builder = builder
.setIoThreads(ioThreads)
.setWorkerThreads(workerThreads)
.setWorkerThreads(0) // starting v8, restheart uses virtual threads
.setDirectBuffers(configuration.coreModule().directBuffers())
.setBufferSize(configuration.coreModule().bufferSize())
.setHandler(HANDLERS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,11 +449,6 @@ core:
# if <= 0, use the number of cores.
io-threads: 0

# Number of threads created for blocking tasks (such as ones involving db access). Suggested value: core*8
# if < 0, use the number of cores * 8.
# This option is only used by restheart native image. In other cases requests are handled by the virtual thread executor.
worker-threads: 0

# 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
5 changes: 0 additions & 5 deletions core/src/main/resources/restheart-default-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -429,11 +429,6 @@ core:
# if <= 0, use the number of cores.
io-threads: 0

# Number of threads created for blocking tasks (such as ones involving db access). Suggested value: core*8
# if < 0, use the number of cores * 8.
# This option is only used by restheart native image. In other cases requests are handled by the virtual thread executor.
worker-threads: 0

# 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

0 comments on commit 1ec4ec0

Please sign in to comment.