Skip to content

Commit 2770c63

Browse files
author
Oleksandr Dzhychko
authored
Merge pull request #647 from modelix/MODELIX-830-option-to-set-response-write-timeout-seconds
feat(model-server): add an option to set the timeout for writing resp…
2 parents 7de66d6 + d8bd962 commit 2770c63

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

model-server/src/main/kotlin/org/modelix/model/server/CmdLineArgs.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ import java.io.File
88
import java.util.LinkedList
99

1010
internal class CmdLineArgs {
11+
12+
companion object {
13+
// When this option was implemented, the default value was 10s
14+
// in [NettyApplicationEngine.Configuration.responseWriteTimeoutSeconds].
15+
// A higher default makes sense because an initial pull of the repository might take longer.
16+
// Two minutes is a default to accommodate most use cases.
17+
private const val DEFAULT_RESPONSE_WRITE_TIMEOUT_SECONDS: Int = 2 * 60
18+
}
19+
1120
@Parameter(names = ["-secret", "--secret"], description = "Path to the secretfile", converter = FileConverter::class)
1221
var secretFile = File("/secrets/modelsecret/modelsecret.txt")
1322

@@ -33,6 +42,13 @@ internal class CmdLineArgs {
3342
@Parameter(names = ["-port", "--port"], description = "Set port", converter = IntegerConverter::class)
3443
var port: Int? = null
3544

45+
@Parameter(
46+
names = ["-response-write-timeout-seconds", "--response-write-timeout-seconds"],
47+
description = "Timeout in seconds for sending responses to clients. Values smaller or equal to 0 disable the timeout. Defaults to $DEFAULT_RESPONSE_WRITE_TIMEOUT_SECONDS seconds if unset.",
48+
converter = IntegerConverter::class,
49+
)
50+
var responseWriteTimeoutSeconds: Int = DEFAULT_RESPONSE_WRITE_TIMEOUT_SECONDS
51+
3652
@Parameter(names = ["-set", "--set"], description = "Set values", arity = 2)
3753
var setValues: List<String> = LinkedList<String>()
3854

model-server/src/main/kotlin/org/modelix/model/server/Main.kt

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,15 @@ object Main {
8686
return
8787
}
8888

89-
LOG.info("Max memory (bytes): " + Runtime.getRuntime().maxMemory())
89+
LOG.info("Max memory (bytes): ${Runtime.getRuntime().maxMemory()}")
9090
LOG.info("Server process started")
91-
LOG.info("In memory: " + cmdLineArgs.inmemory)
92-
LOG.info("Path to secret file: " + cmdLineArgs.secretFile)
93-
LOG.info("Path to JDBC configuration file: " + cmdLineArgs.jdbcConfFile)
94-
LOG.info("Schema initialization: " + cmdLineArgs.schemaInit)
95-
LOG.info("Set values: " + cmdLineArgs.setValues)
96-
LOG.info("Disable Swagger-UI: " + cmdLineArgs.noSwaggerUi)
91+
LOG.info("In memory: ${cmdLineArgs.inmemory}")
92+
LOG.info("Path to secret file: ${cmdLineArgs.secretFile}")
93+
LOG.info("Path to JDBC configuration file: ${cmdLineArgs.jdbcConfFile}")
94+
LOG.info("Schema initialization: ${cmdLineArgs.schemaInit}")
95+
LOG.info("Set values: ${cmdLineArgs.setValues}")
96+
LOG.info("Disable Swagger-UI: ${cmdLineArgs.noSwaggerUi}")
97+
LOG.info("Response write timeout seconds: ${cmdLineArgs.responseWriteTimeoutSeconds}")
9798

9899
if (cmdLineArgs.dumpOutName != null && !cmdLineArgs.inmemory) {
99100
throw RuntimeException("For now dumps are supported only with the inmemory option")
@@ -163,7 +164,12 @@ object Main {
163164
val contentExplorer = ContentExplorer(localModelClient, repositoriesManager)
164165
val modelReplicationServer = ModelReplicationServer(repositoriesManager)
165166
val metricsHandler = MetricsHandler()
166-
val ktorServer: NettyApplicationEngine = embeddedServer(Netty, port = port) {
167+
168+
val configureNetty: NettyApplicationEngine.Configuration.() -> Unit = {
169+
this.responseWriteTimeoutSeconds = cmdLineArgs.responseWriteTimeoutSeconds
170+
}
171+
172+
val ktorServer: NettyApplicationEngine = embeddedServer(Netty, port = port, configure = configureNetty) {
167173
install(Routing)
168174
installAuthentication(unitTestMode = !KeycloakUtils.isEnabled())
169175
install(ForwardedHeaders)

0 commit comments

Comments
 (0)