Application Options
Mach lets you configure application server behavior during startup using AppBuilder::configureApp().
Settings that you do not explicitly change keep their default values.
Configuring the Application
Section titled “Configuring the Application”Use configureApp() to customize application options:
mach::AppBuilder builder;
builder.configureApp([](mach::AppOptions& options) { options.host = "0.0.0.0"; options.port = 8080; options.threadCount = 4; options.requestTimeout = std::chrono::seconds(30);});The host determines the IP address the server binds to when accepting incoming connections.
The default is:
127.0.0.1This makes the server accessible only from the local machine.
To accept connections through all available network interfaces:
builder.configureApp([](mach::AppOptions& options) { options.host = "0.0.0.0";});This is commonly useful when running Mach inside a container or when the application needs to accept connections from other machines.
The port determines the TCP port the server listens on.
The default is:
3143To use a different port:
builder.configureApp([](mach::AppOptions& options) { options.port = 8080;});Choose a port that is available and appropriate for the environment in which the application runs.
Thread Count
Section titled “Thread Count”The threadCount determines the number of worker threads Mach uses to process requests.
The default is:
4To use a different number of worker threads:
builder.configureApp([](mach::AppOptions& options) { options.threadCount = 8;});The appropriate thread count depends on the application’s workload and the environment in which it runs. For most applications, the default is a reasonable starting point.
Request Timeout
Section titled “Request Timeout”The requestTimeout determines how long Mach waits for a request to complete before timing out.
To configure a 30-second request timeout:
builder.configureApp([](mach::AppOptions& options) { options.requestTimeout = std::chrono::seconds(30);});For most applications, the default request timeout is appropriate and does not need to be changed. Adjust it when your application has endpoints that legitimately require more or less time to complete.
Next Steps
Section titled “Next Steps”For details about application configuration, see AppOptions.