% This LaTeX document was generated using the LaTeX backend of PlDoc,
% The SWI-Prolog documentation system



\subsection{library(http/http_dyn_workers): Dynamically schedule HTTP workers.}

\label{sec:httpdynworkers}

This module defines hooks into the HTTP framework to dynamically
schedule worker threads. Dynamic scheduling relieves us from finding a
good value for the size of the HTTP worker pool.

The decision to add a worker follows these rules:

\begin{itemize}
    \item If the load average caused by the worker threads exceeds
http:max_load, no worker is added.
    \item Wait for some time, depending on how close we are to the
http:max_workers limit.

\begin{shortlist}
    \item If the worker is still needed, add it.
\end{shortlist}
\end{itemize}

The policy depends on three settings:

\begin{description}
    \infixtermitem{\Smodule}{\term{http}{}}{\term{max_workers}{}}
The maximum number of workers that will be created. Default is
100.
    \infixtermitem{\Smodule}{\term{http}{}}{\term{worker_idle_limit}{}}
The number of seconds a dynamic worker waits for a new job. If
no job arrives in time it terminates. Default is 10 seconds.
    \infixtermitem{\Smodule}{\term{http}{}}{\term{max_load}{}}
Max load average created by \textbf{the HTTP server}, i.e. the amount
of CPU time consumed per second. Default is 10.
\end{description}

\vspace{0.7cm}

\begin{description}
\qpredicate[multifile]{http}{schedule_workers}{1}{+Dict}Called if there is no immediately free worker to handle the
incomming request. The request is forwarded to the thread
\verb$__http_scheduler$ as the hook is called in time critical code.
\end{description}

