Skip to content

Commit a313d25

Browse files
authored
Merge pull request #2913 from vespa-engine/bjorncs/container-threadpool-configuration
Bjorncs/container threadpool configuration
2 parents d59f03f + 043a966 commit a313d25

File tree

3 files changed

+45
-89
lines changed

3 files changed

+45
-89
lines changed

en/performance/container-tuning.html

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ <h2 id="container-worker-threads">Container worker threads</h2>
2222
Most components including request handlers use the container's <em>default thread pool</em>,
2323
which is controlled by a shared executor instance.
2424
Any component can utilize the default pool by injecting an <code>java.util.concurrent.Executor</code> instance.
25-
Some built-in components have dedicated thread pools - such as the Jetty server, the search handler and the feed handler.
25+
Some built-in components have dedicated thread pools - such as the Jetty server and the search handler.
2626
These thread pools are injected through special wiring in the config model and
2727
are not easily accessible from other components.
2828
</p>
@@ -38,46 +38,45 @@ <h2 id="container-worker-threads">Container worker threads</h2>
3838
<p>
3939
The container will pre-start the minimum number of worker threads,
4040
so even an idle container may report running several hundred threads.
41-
For thread pools with fixed size (<em>min == max</em>), all threads are pre-started.
41+
The thread pool is pre-started with the number of thread specified in the <code>threads</code> parameter.
4242
Note that tuning the capacity upwards increases the risk of high GC pressure
4343
as concurrency becomes higher with more in-flight requests.
4444
The GC pressure is a function of number of in-flight requests, the time it takes to complete the request
4545
and the amount of garbage produced per request.
4646
Increasing the queue size will allow the application to handle shorter traffic bursts without rejecting requests,
4747
although increasing the average latency for those requests that are queued up.
4848
Large queues will also increase heap consumption in overload situations.
49-
Extra threads will be created once the queue is full (if <em>max &gt; min</em>), and are destroyed after an idle timeout.
49+
Extra threads will be created once the queue is full (when <code>boost</code> is specified), and are destroyed after an idle timeout.
5050
If all threads are occupied, requests are rejected with a 503 response.
5151
</p>
5252
<p>
5353
The effective thread pool configuration and utilization statistics can be observed through the
5454
<a href="../operations/container.html#container-metrics">Container Metrics</a>.
5555
See <a href="../operations/container.html#thread-pool-metrics">Thread Pool Metrics</a> for a list of metrics exported.
5656
</p>
57-
<p>Example configuration override:</p>
57+
{% include note.html content=' If the queue size is set to 0 the metric measuring the queue size -
58+
<code>jdisc.thread_pool.work_queue.size</code> - will instead switch to measure how many threads are active.'%}
59+
60+
<h3 id="container-worker-threads-min">Lower limit</h3>
61+
The container will override any configuration if the effective value is below a fixed minimum. This is to
62+
reduce the risk of certain deadlock scenarios and improve concurrency for low-resource environments.
63+
<ul>
64+
<li>Minimum 8 threads.</li>
65+
<li>Minimum 650 queue capacity (if queue is not disabled).</li>
66+
</ul>
67+
68+
<h3 id="container-worker-threads-example">Example</h3>
5869
<pre>{% highlight xml %}
5970
<container id="container" version="1.0">
6071

6172
<search>
6273
<!-- Search handler thread pool -->
6374
<threadpool>
64-
<max-threads>500</max-threads>
65-
<min-threads>500</min-threads>
66-
<queue-size>0</queue-size>
75+
<threads boost="12">4</threads>
76+
<queue>100</queue>
6777
</threadpool>
6878
</search>
6979

70-
<document-api>
71-
<!-- Feed handler thread pool -->
72-
<http-client-api>
73-
<threadpool>
74-
<max-threads>50</max-threads>
75-
<min-threads>10</min-threads>
76-
<queue-size>1000</queue-size>
77-
</threadpool>
78-
</http-client-api>
79-
</document-api>
80-
8180
<!-- Default thread pool -->
8281
<config name="container.handler.threadpool">
8382
<maxthreads>200</maxthreads>

en/reference/services-container.html

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@
5050
<a href="#tracelevel">tracelevel</a>
5151
<a href="#mbusport">mbusport</a>
5252
<a href="#ignore-undefined-fields">ignore-undefined-fields</a>
53-
<a href="#http-client-api">http-client-api</a>
54-
<a href="#http-client-api-threadpool">threadpool</a>
55-
<a href="#http-client-api-threadpool">max-threads</a>
56-
<a href="#http-client-api-threadpool">min-threads</a>
57-
<a href="#http-client-api-threadpool">queue-size</a>
5853
<a href="../stateless-model-evaluation.html">model-evaluation</a>
5954
<a href="../stateless-model-evaluation.html#onnx-inference-options">onnx</a>
6055
<a href="#document">document [type, class, bundle]</a>
@@ -397,13 +392,6 @@ <h2 id="document-api">document-api</h2>
397392
</p>
398393
</td>
399394
</tr>
400-
<tr>
401-
<th>http-client-api</th>
402-
<td>optional</td>
403-
<td></td>
404-
<td></td>
405-
<td><p id="document-api.http-client-api">Configuration for the Vespa HTTP client API</p></td>
406-
</tr>
407395
</tbody>
408396
</table>
409397
<p>Example:</p>
@@ -420,48 +408,11 @@ <h2 id="document-api">document-api</h2>
420408
&lt;route&gt;default&lt;/route&gt;
421409
&lt;timeout&gt;250.5&lt;/timeout&gt;
422410
&lt;tracelevel&gt;3&lt;/tracelevel&gt;
423-
&lt;http-client-api&gt;
424-
&lt;threadpool&gt;
425-
&lt;max-threads&gt;50&lt;/max-threads&gt;
426-
&lt;min-threads&gt;10&lt;/min-threads&gt;
427-
&lt;queue-size&gt;1000&lt;/queue-size&gt;
428-
&lt;/threadpool&gt;
429-
&lt;/http-client-api&gt;
430411
&lt;document-api&gt;
431412
</pre>
432413

433414

434415

435-
<h2 id="http-client-api">http-client-api</h2>
436-
<pre>
437-
&lt;http-client-api&gt;
438-
&lt;threadpool&gt;
439-
&lt;max-threads&gt;50&lt;/max-threads&gt;
440-
&lt;min-threads&gt;10&lt;/min-threads&gt;
441-
&lt;queue-size&gt;1000&lt;/queue-size&gt;
442-
&lt;/threadpool&gt;
443-
&lt;/http-client-api&gt;
444-
</pre>
445-
<p>Children elements:</p>
446-
<table class="table">
447-
<thead>
448-
<tr><th>Name</th><th>Required</th><th>Value</th><th>Default</th><th>Description</th></tr>
449-
</thead><tbody>
450-
<tr><th>threadpool</th>
451-
<td>optional</td>
452-
<td></td>
453-
<td></td>
454-
<td></td>
455-
<td>
456-
<p id="http-client-api-threadpool">
457-
Contains configuration of the threadpool for the http client api handler.
458-
The pool is initialized with minimum number of threads during startup.
459-
Additional threads will be created on demand once the request queue is full.
460-
Requests are rejected once maximum threads are reached, all threads are busy and the request queue is full.
461-
</p>
462-
</td>
463-
</tr></tbody>
464-
</table>
465416

466417

467418

en/reference/services-search.html

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@
3737
<a href="#node">node</a>
3838
<a href="#renderer">renderer [id, class, bundle]</a>
3939
<a href="#threadpool">threadpool</a>
40-
<a href="#threadpool-max-threads">max-threads</a>
41-
<a href="#threadpool-min-threads">min-threads</a>
42-
<a href="#threadpool-queue-size">queue-size</a>
40+
<a href="#threadpool-threads">threads [ boost ]</a>
41+
<a href="#threadpool-queue">queue</a>
4342
</pre>
4443
<p>
4544
<a href="config-files.html#generic-configuration-in-services-xml">config</a>
@@ -597,29 +596,36 @@ <h2 id="node">node</h2>
597596

598597
<h2 id="threadpool">threadpool</h2>
599598
<p>
600-
Contains configuration of the threadpool for the jdisc search handler.
601-
The pool is initialized with minimum number of threads during startup.
602-
Additional threads will be created on demand once the request queue is full.
603-
Requests are rejected once maximum threads are reached, all threads are busy and the request queue is full.
599+
Specifies configuration for the thread pool for the jdisc search handler. All parameters are relative to the number of CPU cores -
600+
if a node has 8 vCPU with <code>threads=4</code>, the thread pool will have 32 threads.
601+
Same for queue size - if <code>queue=10</code>, the queue will have capacity for 80 entries.
602+
If the <code>boost</code> attribute is specified, additional threads will be created on demand once the request queue is full.
603+
These threads are then destructed after idling for a fixed amount of time.
604+
Requests are rejected once the maximum number of allowed threads is reached, all threads are busy and the request queue is full.
605+
See <a href="container-tuning.html">Container Tuning</a> for more details.
604606
</p>
605607

606-
607-
608-
<h2 id="threadpool-max-threads">max-threads</h2>
609-
<p>
610-
Maximum number of threads in pool.
611-
</p>
612-
613-
614-
615-
<h2 id="threadpool-min-threads">min-threads</h2>
608+
<h2 id="threadpool-threads">threads</h2>
616609
<p>
617-
Minimum number of threads in pool.
610+
The number of permanent threads relative to CPU cores. Default value is <code>2</code>.
618611
</p>
612+
<table class="table">
613+
<thead>
614+
<tr><th>Attribute</th><th>Required</th><th>Value</th><th>Default</th><th>Description</th></tr>
615+
</thead><tbody>
616+
<tr><th>boost</th>
617+
<td>optional</td>
618+
<td>number</td>
619+
<td></td>
620+
<td>
621+
<p id="threads.boost">
622+
The number of additional threads relative to CPU cores. Default value is <code>2</code>.
623+
</p>
624+
</td></tr>
625+
</tbody>
626+
</table>
619627

620-
621-
622-
<h2 id="threadpool-queue-size">queue-size</h2>
628+
<h2 id="threadpool-queue">queue</h2>
623629
<p>
624-
Request queue size.
630+
The size of the request queue relative to CPU cores. Specify <code>0</code> to disable queuing. Default value is <code>40</code>.
625631
</p>

0 commit comments

Comments
 (0)