summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2011-05-05 17:56:31 -0400
committerAndreas Schneider <asn@samba.org>2011-08-10 18:14:03 +0200
commit2056d06cae4937c12433d1247b02c346625f86a4 (patch)
treefa27e0b9519cc20a37d6875de82ecc79b92809bc /source3
parentb9354f72291836e155ed5af56ab98b6a8537ceef (diff)
downloadsamba-2056d06cae4937c12433d1247b02c346625f86a4.tar.gz
samba-2056d06cae4937c12433d1247b02c346625f86a4.tar.bz2
samba-2056d06cae4937c12433d1247b02c346625f86a4.zip
s3-prefork: add way to manage number of clients per child
The allowed_clients var is a parent managed variable that tell children how many clients they are allowed to handle at the same time. This way children can overcommit but within parent controlled limits. Signed-off-by: Andreas Schneider <asn@samba.org>
Diffstat (limited to 'source3')
-rw-r--r--source3/lib/server_prefork.c35
-rw-r--r--source3/lib/server_prefork.h6
2 files changed, 38 insertions, 3 deletions
diff --git a/source3/lib/server_prefork.c b/source3/lib/server_prefork.c
index b337fa0c3b..0a8199a6ea 100644
--- a/source3/lib/server_prefork.c
+++ b/source3/lib/server_prefork.c
@@ -36,6 +36,8 @@ struct prefork_pool {
int pool_size;
struct pf_worker_data *pool;
+
+ int allowed_clients;
};
int prefork_pool_destructor(struct prefork_pool *pfp)
@@ -86,6 +88,10 @@ bool prefork_create_pool(struct tevent_context *ev_ctx,
talloc_set_destructor(pfp, prefork_pool_destructor);
for (i = 0; i < min_children; i++) {
+
+ pfp->pool[i].allowed_clients = 1;
+ pfp->pool[i].started = now;
+
pid = sys_fork();
switch (pid) {
case -1:
@@ -102,7 +108,6 @@ bool prefork_create_pool(struct tevent_context *ev_ctx,
default: /* THE PARENT */
pfp->pool[i].pid = pid;
- pfp->pool[i].started = now;
break;
}
}
@@ -126,6 +131,9 @@ int prefork_add_children(struct tevent_context *ev_ctx,
continue;
}
+ pfp->pool[i].allowed_clients = 1;
+ pfp->pool[i].started = now;
+
pid = sys_fork();
switch (pid) {
case -1:
@@ -144,7 +152,6 @@ int prefork_add_children(struct tevent_context *ev_ctx,
default: /* THE PARENT */
pfp->pool[i].pid = pid;
- pfp->pool[i].started = now;
j++;
break;
}
@@ -263,6 +270,30 @@ bool prefork_mark_pid_dead(struct prefork_pool *pfp, pid_t pid)
return false;
}
+void prefork_increase_allowed_clients(struct prefork_pool *pfp, int max)
+{
+ int i;
+
+ for (i = 0; i < pfp->pool_size; i++) {
+ if (pfp->pool[i].status == PF_WORKER_NONE) {
+ continue;
+ }
+
+ if (pfp->pool[i].allowed_clients < max) {
+ pfp->pool[i].allowed_clients++;
+ }
+ }
+}
+
+void prefork_reset_allowed_clients(struct prefork_pool *pfp)
+{
+ int i;
+
+ for (i = 0; i < pfp->pool_size; i++) {
+ pfp->pool[i].allowed_clients = 1;
+ }
+}
+
/* ==== Functions used by children ==== */
static SIG_ATOMIC_T pf_alarm;
diff --git a/source3/lib/server_prefork.h b/source3/lib/server_prefork.h
index 7e95602e81..bf9f3d3fe7 100644
--- a/source3/lib/server_prefork.h
+++ b/source3/lib/server_prefork.h
@@ -37,10 +37,12 @@ enum pf_server_cmds {
struct pf_worker_data {
pid_t pid;
enum pf_worker_status status;
- enum pf_server_cmds cmds;
time_t started;
time_t last_used;
int num_clients;
+
+ enum pf_server_cmds cmds;
+ int allowed_clients;
};
typedef int (prefork_main_fn_t)(struct tevent_context *ev,
@@ -67,6 +69,8 @@ int prefork_retire_children(struct prefork_pool *pfp,
int num_children, time_t age_limit);
int prefork_count_active_children(struct prefork_pool *pfp, int *total);
bool prefork_mark_pid_dead(struct prefork_pool *pfp, pid_t pid);
+void prefork_increase_allowed_clients(struct prefork_pool *pfp, int max);
+void prefork_reset_allowed_clients(struct prefork_pool *pfp);
/* ==== Functions used by children ==== */