MCPcopy Create free account
hub / github.com/apache/httpd / worker_run

Function worker_run

server/mpm/worker/worker.c:1748–1955  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1746}
1747
1748static int worker_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
1749{
1750 int num_buckets = retained->mpm->num_buckets;
1751 int remaining_children_to_start;
1752 int i;
1753
1754 ap_log_pid(pconf, ap_pid_fname);
1755
1756 if (!retained->mpm->was_graceful) {
1757 if (ap_run_pre_mpm(s->process->pool, SB_SHARED) != OK) {
1758 retained->mpm->mpm_state = AP_MPMQ_STOPPING;
1759 return !OK;
1760 }
1761 /* fix the generation number in the global score; we just got a new,
1762 * cleared scoreboard
1763 */
1764 ap_scoreboard_image->global->running_generation = retained->mpm->my_generation;
1765 }
1766
1767 ap_unixd_mpm_set_signals(pconf, one_process);
1768
1769 /* Don't thrash since num_buckets depends on the
1770 * system and the number of online CPU cores...
1771 */
1772 if (ap_daemons_limit < num_buckets)
1773 ap_daemons_limit = num_buckets;
1774 if (ap_daemons_to_start < num_buckets)
1775 ap_daemons_to_start = num_buckets;
1776 /* We want to create as much children at a time as the number of buckets,
1777 * so to optimally accept connections (evenly distributed across buckets).
1778 * Thus min_spare_threads should at least maintain num_buckets children,
1779 * and max_spare_threads allow num_buckets more children w/o triggering
1780 * immediately (e.g. num_buckets idle threads margin, one per bucket).
1781 */
1782 if (min_spare_threads < threads_per_child * (num_buckets - 1) + num_buckets)
1783 min_spare_threads = threads_per_child * (num_buckets - 1) + num_buckets;
1784 if (max_spare_threads < min_spare_threads + (threads_per_child + 1) * num_buckets)
1785 max_spare_threads = min_spare_threads + (threads_per_child + 1) * num_buckets;
1786
1787 /* If we're doing a graceful_restart then we're going to see a lot
1788 * of children exiting immediately when we get into the main loop
1789 * below (because we just sent them AP_SIG_GRACEFUL). This happens pretty
1790 * rapidly... and for each one that exits we may start a new one, until
1791 * there are at least min_spare_threads idle threads, counting across
1792 * all children. But we may be permitted to start more children than
1793 * that, so we'll just keep track of how many we're
1794 * supposed to start up without the 1 second penalty between each fork.
1795 */
1796 remaining_children_to_start = ap_daemons_to_start;
1797 if (remaining_children_to_start > ap_daemons_limit) {
1798 remaining_children_to_start = ap_daemons_limit;
1799 }
1800 if (!retained->mpm->was_graceful) {
1801 startup_children(remaining_children_to_start);
1802 remaining_children_to_start = 0;
1803 }
1804 else {
1805 /* give the system some time to recover before kicking into

Callers

nothing calls this directly

Calls 15

ap_log_pidFunction · 0.85
ap_unixd_mpm_set_signalsFunction · 0.85
ap_get_server_builtFunction · 0.85
ap_log_command_lineFunction · 0.85
ap_log_mpm_commonFunction · 0.85
ap_mpm_podx_killpgFunction · 0.85
ap_remove_pidFunction · 0.85
ap_close_listenersFunction · 0.85
ap_mpm_safe_killFunction · 0.85

Tested by

no test coverage detected