2 Unix SMB/Netbios implementation.
4 Copyright (C) Simo Sorce <idra@samba.org> 2011
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "lib/server_prefork.h"
22 #include "lib/server_prefork_util.h"
24 void pfh_daemon_config(const char *daemon_name
,
25 struct pf_daemon_config
*cfg
,
26 struct pf_daemon_config
*default_cfg
)
28 int min
, max
, rate
, allow
, life
;
30 min
= lp_parm_int(GLOBAL_SECTION_SNUM
,
32 "prefork_min_children",
33 default_cfg
->min_children
);
34 max
= lp_parm_int(GLOBAL_SECTION_SNUM
,
36 "prefork_max_children",
37 default_cfg
->max_children
);
38 rate
= lp_parm_int(GLOBAL_SECTION_SNUM
,
41 default_cfg
->spawn_rate
);
42 allow
= lp_parm_int(GLOBAL_SECTION_SNUM
,
44 "prefork_max_allowed_clients",
45 default_cfg
->max_allowed_clients
);
46 life
= lp_parm_int(GLOBAL_SECTION_SNUM
,
48 "prefork_child_min_life",
49 default_cfg
->child_min_life
);
51 if (max
> cfg
->max_children
&& cfg
->max_children
!= 0) {
52 cfg
->prefork_status
|= PFH_NEW_MAX
;
55 cfg
->min_children
= min
;
56 cfg
->max_children
= max
;
57 cfg
->spawn_rate
= rate
;
58 cfg
->max_allowed_clients
= allow
;
59 cfg
->child_min_life
= life
;
62 void pfh_manage_pool(struct tevent_context
*ev_ctx
,
63 struct messaging_context
*msg_ctx
,
64 struct pf_daemon_config
*cfg
,
65 struct prefork_pool
*pool
)
67 time_t now
= time(NULL
);
71 if ((cfg
->prefork_status
& PFH_NEW_MAX
) &&
72 !(cfg
->prefork_status
& PFH_ENOSPC
)) {
73 ret
= prefork_expand_pool(pool
, cfg
->max_children
);
75 cfg
->prefork_status
|= PFH_ENOSPC
;
77 cfg
->prefork_status
&= ~PFH_NEW_MAX
;
80 active
= prefork_count_active_children(pool
, &total
);
82 if ((total
< cfg
->max_children
) &&
83 ((total
< cfg
->min_children
) ||
84 (total
- active
< cfg
->spawn_rate
))) {
85 n
= prefork_add_children(ev_ctx
, msg_ctx
,
86 pool
, cfg
->spawn_rate
);
87 if (n
< cfg
->spawn_rate
) {
88 DEBUG(10, ("Tried to start %d children but only,"
89 "%d were actually started.!\n",
94 if (total
- active
> cfg
->min_children
) {
95 if ((total
- cfg
->min_children
) >= cfg
->spawn_rate
) {
96 prefork_retire_children(pool
, cfg
->spawn_rate
,
97 now
- cfg
->child_min_life
);
101 n
= prefork_count_allowed_connections(pool
);
102 if (n
<= cfg
->spawn_rate
) {
104 prefork_increase_allowed_clients(pool
,
105 cfg
->max_allowed_clients
);
106 n
= prefork_count_allowed_connections(pool
);
107 } while (n
<= cfg
->spawn_rate
);
108 } else if (n
> cfg
->max_children
+ cfg
->spawn_rate
) {
110 prefork_decrease_allowed_clients(pool
);
111 n
= prefork_count_allowed_connections(pool
);
112 } while (n
> cfg
->max_children
+ cfg
->spawn_rate
);
115 DEBUG(10, ("Stats: children: %d, allowed connections: %d\n",
116 total
, prefork_count_allowed_connections(pool
)));