mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-09-06 13:41:28 +00:00
fixed multithreading + max-requests
This commit is contained in:
@@ -178,12 +178,12 @@ void master_loop(char **argv, char **environ) {
|
||||
|
||||
/* route signals to workers... */
|
||||
uwsgi_unix_signal(SIGHUP, grace_them_all);
|
||||
signal(SIGTERM, (void *) &reap_them_all);
|
||||
signal(SIGINT, (void *) &kill_them_all);
|
||||
signal(SIGQUIT, (void *) &kill_them_all);
|
||||
uwsgi_unix_signal(SIGTERM, reap_them_all);
|
||||
uwsgi_unix_signal(SIGINT, kill_them_all);
|
||||
uwsgi_unix_signal(SIGQUIT, kill_them_all);
|
||||
/* used only to avoid human-errors */
|
||||
|
||||
signal(SIGUSR1, (void *) &stats);
|
||||
uwsgi_unix_signal(SIGUSR1, stats);
|
||||
|
||||
uwsgi.master_queue = event_queue_init();
|
||||
|
||||
@@ -426,7 +426,7 @@ void master_loop(char **argv, char **environ) {
|
||||
uwsgi_error("waitpid()");
|
||||
/* here is better to reload all the uWSGI stack */
|
||||
uwsgi_log( "something horrible happened...\n");
|
||||
reap_them_all();
|
||||
reap_them_all(0);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
@@ -524,7 +524,7 @@ void master_loop(char **argv, char **environ) {
|
||||
if (byte == 0) {
|
||||
close(uwsgi.emperor_fd);
|
||||
uwsgi.has_emperor = 0;
|
||||
kill_them_all();
|
||||
kill_them_all(0);
|
||||
}
|
||||
// reload me
|
||||
else if (byte == 1) {
|
||||
@@ -535,7 +535,7 @@ void master_loop(char **argv, char **environ) {
|
||||
uwsgi_log("lost connection with my emperor !!!\n");
|
||||
close(uwsgi.emperor_fd);
|
||||
uwsgi.has_emperor = 0;
|
||||
kill_them_all();
|
||||
kill_them_all(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -713,16 +713,6 @@ void master_loop(char **argv, char **environ) {
|
||||
// recalculate requests counter on race conditions risky configurations
|
||||
// a bit of inaccuracy is better than locking;)
|
||||
|
||||
if (uwsgi.cores > 1) {
|
||||
for(i=1;i<uwsgi.numproc+1;i++) {
|
||||
tmp_counter = 0;
|
||||
for(j=0;j<uwsgi.cores;j++) {
|
||||
tmp_counter += uwsgi.core[j]->requests;
|
||||
}
|
||||
uwsgi.workers[i].requests = tmp_counter;
|
||||
}
|
||||
}
|
||||
|
||||
if (uwsgi.numproc > 1) {
|
||||
tmp_counter = 0;
|
||||
for(i=1;i<uwsgi.numproc+1;i++) {
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
def application(env, start_response):
|
||||
while 1:
|
||||
pass
|
||||
@@ -394,10 +394,6 @@ void uwsgi_close_request(struct wsgi_request *wsgi_req) {
|
||||
uwsgi.workers[0].requests++;
|
||||
uwsgi.workers[uwsgi.mywid].requests++;
|
||||
|
||||
if (uwsgi.cores > 1) {
|
||||
uwsgi.core[wsgi_req->async_id]->requests++;
|
||||
}
|
||||
|
||||
// after_request hook
|
||||
if (uwsgi.p[wsgi_req->uh.modifier1]->after_request) uwsgi.p[wsgi_req->uh.modifier1]->after_request(wsgi_req);
|
||||
|
||||
@@ -504,7 +500,7 @@ polling:
|
||||
if (read(uwsgi.sockets_poll[uwsgi.sockets_cnt].fd, &uwsgi_signal, 1) <= 0) {
|
||||
if (uwsgi.no_orphans) {
|
||||
uwsgi_log_verbose("uWSGI worker %d screams: UAAAAAAH my master died, i will follow him...\n", uwsgi.mywid);
|
||||
end_me();
|
||||
end_me(0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -195,16 +195,16 @@ void gracefully_kill(int signum)
|
||||
if (UWSGI_IS_IN_REQUEST) {
|
||||
uwsgi.workers[uwsgi.mywid].manage_next_request = 0;
|
||||
} else {
|
||||
reload_me();
|
||||
reload_me(0);
|
||||
}
|
||||
}
|
||||
|
||||
void reload_me()
|
||||
void reload_me(int signum)
|
||||
{
|
||||
exit(UWSGI_RELOAD_CODE);
|
||||
}
|
||||
|
||||
void end_me()
|
||||
void end_me(int signum)
|
||||
{
|
||||
exit(UWSGI_END_CODE);
|
||||
}
|
||||
@@ -215,7 +215,7 @@ void goodbye_cruel_world()
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void kill_them_all()
|
||||
void kill_them_all(int signum)
|
||||
{
|
||||
int i;
|
||||
uwsgi.to_hell = 1;
|
||||
@@ -267,18 +267,18 @@ void grace_them_all(int signum)
|
||||
void uwsgi_nuclear_blast() {
|
||||
|
||||
if (!uwsgi.workers) {
|
||||
reap_them_all();
|
||||
reap_them_all(0);
|
||||
}
|
||||
else if (uwsgi.master_process) {
|
||||
if (getpid() == uwsgi.workers[0].pid) {
|
||||
reap_them_all();
|
||||
reap_them_all(0);
|
||||
}
|
||||
}
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void reap_them_all()
|
||||
void reap_them_all(int signum)
|
||||
{
|
||||
int i;
|
||||
uwsgi.to_heaven = 1;
|
||||
@@ -313,7 +313,7 @@ void harakiri()
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void stats()
|
||||
void stats(int signum)
|
||||
{
|
||||
//fix this for better logging(this cause races)
|
||||
struct uwsgi_app *ua = NULL;
|
||||
@@ -922,6 +922,7 @@ options_parsed:
|
||||
if (uwsgi.ns) {
|
||||
for(;;) {
|
||||
char stack[PTHREAD_STACK_MIN];
|
||||
int waitpid_status;
|
||||
uwsgi_log("*** jailing uWSGI in %s ***\n", uwsgi.ns);
|
||||
pid_t pid = clone(uwsgi_start, stack+PTHREAD_STACK_MIN, SIGCHLD|CLONE_NEWUTS|CLONE_NEWPID|CLONE_NEWIPC|CLONE_NEWNS, (void *)argv);
|
||||
if (pid == -1) {
|
||||
@@ -929,11 +930,17 @@ options_parsed:
|
||||
exit(1);
|
||||
}
|
||||
uwsgi_log("waiting for jailed master (pid: %d) death...\n", (int) pid);
|
||||
pid = waitpid(pid, NULL, 0);
|
||||
pid = waitpid(pid, &waitpid_status, 0);
|
||||
if (pid < 0) {
|
||||
uwsgi_error("waitpid()");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// in Linux this is reliable
|
||||
if (WIFEXITED(waitpid_status) && WEXITSTATUS(waitpid_status) == 1) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
uwsgi_log("pid %d ended. Respawning...\n", (int) pid);
|
||||
}
|
||||
}
|
||||
@@ -990,6 +997,11 @@ int uwsgi_start(void *v_argv) {
|
||||
int unmounted = 1;
|
||||
char *delim0, *delim1;
|
||||
|
||||
if (chdir(uwsgi.ns)) {
|
||||
uwsgi_error("chdir()");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
while(unmounted) {
|
||||
|
||||
unmounted = 0;
|
||||
@@ -1023,16 +1035,28 @@ int uwsgi_start(void *v_argv) {
|
||||
if (chdir(ns_tmp_mountpoint)) {
|
||||
uwsgi_error("chdir()");
|
||||
}
|
||||
|
||||
|
||||
if (pivot_root(".", ns_tmp_mountpoint2)) {
|
||||
uwsgi_error("pivot_root()");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (chdir("/")) {
|
||||
uwsgi_error("chdir()");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (umount("/.uwsgi_ns_tmp_mountpoint")) {
|
||||
uwsgi_error("umount tmp()");
|
||||
uwsgi_error("umount /.uwsgi_ns_tmp_mountpoint");
|
||||
}
|
||||
|
||||
rmdir("/.uwsgi_ns_tmp_mountpoint/.uwsgi_ns_tmp_mountpoint");
|
||||
rmdir("/.uwsgi_ns_tmp_mountpoint");
|
||||
if (rmdir("/.uwsgi_ns_tmp_mountpoint/.uwsgi_ns_tmp_mountpoint")) {
|
||||
uwsgi_error("rmdir()");
|
||||
}
|
||||
if (rmdir("/.uwsgi_ns_tmp_mountpoint")) {
|
||||
uwsgi_error("rmdir()");
|
||||
}
|
||||
|
||||
free(ns_tmp_mountpoint2);
|
||||
free(ns_tmp_mountpoint);
|
||||
@@ -1875,11 +1899,11 @@ uwsgi.shared->hooks[UWSGI_MODIFIER_PING] = uwsgi_request_ping; //100
|
||||
signal(SIGALRM, (void *) &harakiri);
|
||||
}
|
||||
uwsgi_unix_signal(SIGHUP, gracefully_kill);
|
||||
signal(SIGINT, (void *) &end_me);
|
||||
signal(SIGTERM, (void *) &reload_me);
|
||||
uwsgi_unix_signal(SIGINT, end_me);
|
||||
uwsgi_unix_signal(SIGTERM, reload_me);
|
||||
|
||||
|
||||
signal(SIGUSR1, (void *) &stats);
|
||||
uwsgi_unix_signal(SIGUSR1, stats);
|
||||
|
||||
signal(SIGUSR2, (void *) &what_i_am_doing);
|
||||
|
||||
@@ -1981,7 +2005,7 @@ uwsgi.shared->hooks[UWSGI_MODIFIER_PING] = uwsgi_request_ping; //100
|
||||
|
||||
end:
|
||||
if (uwsgi.workers[uwsgi.mywid].manage_next_request == 0) {
|
||||
reload_me();
|
||||
reload_me(0);
|
||||
} else {
|
||||
goodbye_cruel_world();
|
||||
}
|
||||
|
||||
@@ -1127,7 +1127,7 @@ struct uwsgi_core {
|
||||
|
||||
time_t harakiri;
|
||||
|
||||
uint64_t requests;
|
||||
//uint64_t requests;
|
||||
uint64_t failed_requests;
|
||||
|
||||
//multiple ts per - core are needed only with multiple_interpreter + threads
|
||||
@@ -1166,11 +1166,11 @@ void warn_pipe(void);
|
||||
void what_i_am_doing(void);
|
||||
void goodbye_cruel_world(void);
|
||||
void gracefully_kill(int);
|
||||
void reap_them_all(void);
|
||||
void kill_them_all(void);
|
||||
void reap_them_all(int);
|
||||
void kill_them_all(int);
|
||||
void grace_them_all(int);
|
||||
void reload_me(void);
|
||||
void end_me(void);
|
||||
void reload_me(int);
|
||||
void end_me(int);
|
||||
int bind_to_unix(char *, int, int, int);
|
||||
int bind_to_tcp(char *, int, char *);
|
||||
int bind_to_udp(char *, int, int);
|
||||
@@ -1190,7 +1190,7 @@ void log_request(struct wsgi_request *);
|
||||
void get_memusage(void);
|
||||
void harakiri(void);
|
||||
|
||||
void stats(void);
|
||||
void stats(int);
|
||||
|
||||
#ifdef UWSGI_XML
|
||||
void uwsgi_xml_config(struct wsgi_request *, int, char *[]);
|
||||
|
||||
Reference in New Issue
Block a user