Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,26 @@ static int on_config_temp_buffer_path(h2o_configurator_command_t *cmd, h2o_confi
return 0;
}

static int on_config_temp_buffer_threshold(h2o_configurator_command_t *cmd, h2o_configurator_context_t *ctx, yoml_t *node)
{
/* if "OFF", disable temp buffers by setting the threshold to SIZE_MAX */
if (strcasecmp(node->data.scalar, "OFF") == 0) {
h2o_socket_buffer_mmap_settings.threshold = SIZE_MAX;
return 0;
}

/* if not "OFF", it could be a number */
if (h2o_configurator_scanf(cmd, node, "%zu", &h2o_socket_buffer_mmap_settings.threshold) != 0)
return -1;

if (h2o_socket_buffer_mmap_settings.threshold < 1048576) {
h2o_configurator_errprintf(cmd, node, "threshold is too low (must be >= 1048576; OFF to disable)");
return -1;
}

return 0;
}

static int on_config_crash_handler(h2o_configurator_command_t *cmd, h2o_configurator_context_t *ctx, yoml_t *node)
{
conf.crash_handler = h2o_strdup(NULL, node->data.scalar, SIZE_MAX).base;
Expand Down Expand Up @@ -1873,6 +1893,8 @@ static void setup_configurators(void)
on_config_num_ocsp_updaters);
h2o_configurator_define_command(c, "temp-buffer-path", H2O_CONFIGURATOR_FLAG_GLOBAL | H2O_CONFIGURATOR_FLAG_EXPECT_SCALAR,
on_config_temp_buffer_path);
h2o_configurator_define_command(c, "temp-buffer-threshold", H2O_CONFIGURATOR_FLAG_GLOBAL | H2O_CONFIGURATOR_FLAG_EXPECT_SCALAR,
on_config_temp_buffer_threshold);
h2o_configurator_define_command(c, "crash-handler", H2O_CONFIGURATOR_FLAG_GLOBAL | H2O_CONFIGURATOR_FLAG_EXPECT_SCALAR,
on_config_crash_handler);
h2o_configurator_define_command(c, "crash-handler.wait-pipe-close",
Expand Down
26 changes: 25 additions & 1 deletion srcdoc/configure/base_directives.mt
Original file line number Diff line number Diff line change
Expand Up @@ -673,12 +673,14 @@ $ctx->{directive}->(
since => "2.0",
see_also => render_mt(<<'EOT'),
<a href="configure/base_directives.html#user"><code>user</code></a>
<a href="configure/base_directives.html#temp-buffer-threshold"><code>temp-buffer-threshold</code></a>
EOT
)->(sub {
?>
<p>
H2O uses an internal structure called <code>h2o_buffer_t</code> for buffering various kinds of data (e.g. POST content, response from upstream HTTP or FastCGI server).
When amount of the data allocated in the buffer exceeds 32MB, it starts allocating storage from the directory pointed to by the directive.
When amount of the data allocated in the buffer exceeds the default value of 32MB, it starts allocating storage from the directory pointed to by the directive.
The threshold can be tuned or disabled using the <code>temp-buffer-threshold</code> directive.
</p>
<p>
By using the directive, users can set the directory to one within a memory-backed file system (e.g. <a href="https://en.wikipedia.org/wiki/Tmpfs">tmpfs</a>) for speed, or specify a disk-based file system to avoid memory pressure.
Expand All @@ -688,6 +690,28 @@ Note that the directory must be writable by the running user of the server.
</p>
? })

<?
$ctx->{directive}->(
name => "temp-buffer-threshold",
levels => [ qw(global) ],
desc => q{Minimum size to offload a large memory allocation to a temporary buffer.},
default => q{temp-buffer-threshold: "33554432"},
since => "2.2.5",
see_also => render_mt(<<'EOT'),
<a href="configure/base_directives.html#temp-buffer-path"><code>temp-buffer-path</code></a>
EOT
)->(sub {
?>
<p>
Users can use this directive to tune the threshold for when the server should use temporary buffers.
The minimum value accepted is 1MB (1048576) to avoid overusing these buffers, which will lead to performance degradation.
If omitted, the default of 32MB is used.
</p>
<p>
The user can disable temporary buffers altogether by setting this threshold to <code>OFF</code>.
</p>
? })

<?
$ctx->{directive}->(
name => "user",
Expand Down