mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-09-06 21:51:30 +00:00
Merge pull request #690 from vine/async_1_2.1
Allow --async 1 (i.e. sync mode, but with a different loop engine)
This commit is contained in:
@@ -54,7 +54,7 @@ def uwsgi_pypy_greenlet_switch(wsgi_req):
|
||||
# update current running greenlet
|
||||
lib.uwsgi.wsgi_req = wsgi_req
|
||||
|
||||
if lib.uwsgi.async <= 1:
|
||||
if lib.uwsgi.async < 1:
|
||||
raise Exception("pypy greenlets require async mode !!!")
|
||||
lib.uwsgi.schedule_to_main = uwsgi_pypy_greenlet_switch
|
||||
lib.uwsgi.schedule_to_req = uwsgi_pypy_greenlet_schedule
|
||||
|
||||
+4
-4
@@ -165,7 +165,7 @@ static void async_expire_timeouts(uint64_t now) {
|
||||
|
||||
int async_add_fd_read(struct wsgi_request *wsgi_req, int fd, int timeout) {
|
||||
|
||||
if (uwsgi.async < 2 || !uwsgi.async_waiting_fd_table){
|
||||
if (uwsgi.async < 1 || !uwsgi.async_waiting_fd_table){
|
||||
uwsgi_log_verbose("ASYNC call without async mode !!!\n");
|
||||
return -1;
|
||||
}
|
||||
@@ -257,7 +257,7 @@ static int async_wait_fd_read2(int fd0, int fd1, int timeout, int *fd) {
|
||||
|
||||
void async_add_timeout(struct wsgi_request *wsgi_req, int timeout) {
|
||||
|
||||
if (uwsgi.async < 2 || !uwsgi.rb_async_timeouts) {
|
||||
if (uwsgi.async < 1 || !uwsgi.rb_async_timeouts) {
|
||||
uwsgi_log_verbose("ASYNC call without async mode !!!\n");
|
||||
return;
|
||||
}
|
||||
@@ -272,7 +272,7 @@ void async_add_timeout(struct wsgi_request *wsgi_req, int timeout) {
|
||||
|
||||
int async_add_fd_write(struct wsgi_request *wsgi_req, int fd, int timeout) {
|
||||
|
||||
if (uwsgi.async < 2 || !uwsgi.async_waiting_fd_table) {
|
||||
if (uwsgi.async < 1 || !uwsgi.async_waiting_fd_table) {
|
||||
uwsgi_log_verbose("ASYNC call without async mode !!!\n");
|
||||
return -1;
|
||||
}
|
||||
@@ -406,7 +406,7 @@ static int uwsgi_async_wait_milliseconds_hook(int timeout) {
|
||||
|
||||
void async_loop() {
|
||||
|
||||
if (uwsgi.async < 2) {
|
||||
if (uwsgi.async < 1) {
|
||||
uwsgi_log("the async loop engine requires async mode (--async <n>)\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
+2
-2
@@ -106,7 +106,7 @@ void uwsgi_init_default() {
|
||||
|
||||
uwsgi.forkbomb_delay = 2;
|
||||
|
||||
uwsgi.async = 1;
|
||||
uwsgi.async = 0;
|
||||
uwsgi.listen_queue = 100;
|
||||
|
||||
uwsgi.cheaper_overload = 3;
|
||||
@@ -419,7 +419,7 @@ pid_t uwsgi_daemonize2() {
|
||||
// fix/check related options
|
||||
void sanitize_args() {
|
||||
|
||||
if (uwsgi.async > 1) {
|
||||
if (uwsgi.async > 0) {
|
||||
uwsgi.cores = uwsgi.async;
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -1228,7 +1228,7 @@ void gracefully_kill(int signum) {
|
||||
}
|
||||
|
||||
// still not found a way to gracefully reload in async mode
|
||||
if (uwsgi.async > 1) {
|
||||
if (uwsgi.async > 0) {
|
||||
exit(UWSGI_RELOAD_CODE);
|
||||
}
|
||||
|
||||
@@ -2669,7 +2669,7 @@ int uwsgi_start(void *v_argv) {
|
||||
}
|
||||
}
|
||||
|
||||
if (uwsgi.async > 1) {
|
||||
if (uwsgi.async > 0) {
|
||||
if ((unsigned long) uwsgi.max_fd < (unsigned long) uwsgi.async) {
|
||||
uwsgi_log_initial("- your current max open files limit is %lu, this is lower than requested async cores !!! -\n", (unsigned long) uwsgi.max_fd);
|
||||
uwsgi.rl.rlim_cur = uwsgi.async;
|
||||
@@ -2977,7 +2977,7 @@ unsafe:
|
||||
uwsgi_log("*** Operational MODE: threaded ***\n");
|
||||
}
|
||||
}
|
||||
else if (uwsgi.async > 1) {
|
||||
else if (uwsgi.async > 0) {
|
||||
if (uwsgi.numproc > 1) {
|
||||
uwsgi_log("*** Operational MODE: preforking+async ***\n");
|
||||
}
|
||||
@@ -3345,7 +3345,7 @@ void uwsgi_worker_run() {
|
||||
// some apps could be mounted only on specific workers
|
||||
uwsgi_init_worker_mount_apps();
|
||||
|
||||
if (uwsgi.async > 1) {
|
||||
if (uwsgi.async > 0) {
|
||||
// a stack of unused cores
|
||||
uwsgi.async_queue_unused = uwsgi_malloc(sizeof(struct wsgi_request *) * uwsgi.async);
|
||||
|
||||
@@ -3485,7 +3485,7 @@ void uwsgi_ignition() {
|
||||
uwsgi_log("your loop engine died. R.I.P.\n");
|
||||
}
|
||||
else {
|
||||
if (uwsgi.async < 2) {
|
||||
if (uwsgi.async < 1) {
|
||||
simple_loop();
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -314,7 +314,7 @@ static void asyncio_loop() {
|
||||
|
||||
uwsgi.schedule_fix = uwsgi_asyncio_schedule_fix;
|
||||
|
||||
if (uwsgi.async < 2) {
|
||||
if (uwsgi.async < 1) {
|
||||
uwsgi_log("the asyncio loop engine requires async mode (--async <n>)\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -731,7 +731,7 @@ clear2:
|
||||
|
||||
// now wait for process exit/death
|
||||
// in async mode we need a trick...
|
||||
if (uwsgi.async > 1) {
|
||||
if (uwsgi.async > 0) {
|
||||
pid_t diedpid = waitpid(cgi_pid, &waitpid_status, WNOHANG);
|
||||
if (diedpid < 0) {
|
||||
uwsgi_error("waitpid()");
|
||||
|
||||
@@ -356,7 +356,7 @@ static void coroae_wait_condvar(SV *cv) {
|
||||
|
||||
static void coroae_loop() {
|
||||
|
||||
if (uwsgi.async < 2) {
|
||||
if (uwsgi.async < 1) {
|
||||
if (uwsgi.mywid == 1) {
|
||||
uwsgi_log("the Coro::AnyEvent loop engine requires async mode (--async <n>)\n");
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ static int fiber_init() {
|
||||
static void fiber_init_apps(void) {
|
||||
|
||||
if (!ufiber.enabled) return;
|
||||
if (uwsgi.async <= 1) {
|
||||
if (uwsgi.async < 1) {
|
||||
uwsgi_log("the fiber loop engine requires async mode\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -368,7 +368,7 @@ static void gevent_loop() {
|
||||
|
||||
struct uwsgi_socket *uwsgi_sock = uwsgi.sockets;
|
||||
|
||||
if (uwsgi.async < 2) {
|
||||
if (uwsgi.async < 1) {
|
||||
uwsgi_log("the gevent loop engine requires async mode (--async <n>)\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -270,7 +270,7 @@ static int uwsgi_glusterfs_request(struct wsgi_request *wsgi_req) {
|
||||
// skip body on HEAD
|
||||
if (uwsgi_strncmp(wsgi_req->method, wsgi_req->method_len, "HEAD", 4)) {
|
||||
size_t remains = st.st_size;
|
||||
if (uwsgi.async > 1) {
|
||||
if (uwsgi.async > 0) {
|
||||
if (uwsgi_glusterfs_read_async(wsgi_req, fd, remains)) goto end;
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -116,7 +116,7 @@ static void greenlet_init_apps(void) {
|
||||
|
||||
if (!ugl.enabled) return;
|
||||
|
||||
if (uwsgi.async <= 1) {
|
||||
if (uwsgi.async < 1) {
|
||||
uwsgi_log("the greenlet suspend engine requires async mode\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -843,7 +843,7 @@ static int uwsgi_lua_request(struct wsgi_request *wsgi_req) {
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
lua_pushvalue(L, -1);
|
||||
if (uwsgi.async > 1) {
|
||||
if (uwsgi.async > 0) {
|
||||
return UWSGI_AGAIN;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -405,7 +405,7 @@ SV *build_psgi_env(struct wsgi_request *wsgi_req) {
|
||||
|
||||
if (!hv_store(env, "psgi.run_once", 13, newSViv(0), 0)) goto clear;
|
||||
|
||||
if (uwsgi.async > 1) {
|
||||
if (uwsgi.async > 0) {
|
||||
if (!hv_store(env, "psgi.nonblocking", 16, newSViv(1), 0)) goto clear;
|
||||
}
|
||||
else {
|
||||
@@ -631,7 +631,7 @@ int uwsgi_perl_request(struct wsgi_request *wsgi_req) {
|
||||
}
|
||||
|
||||
while (psgi_response(wsgi_req, wsgi_req->async_result) != UWSGI_OK) {
|
||||
if (uwsgi.async > 1) {
|
||||
if (uwsgi.async > 0) {
|
||||
FREETMPS;
|
||||
LEAVE;
|
||||
return UWSGI_AGAIN;
|
||||
@@ -861,7 +861,7 @@ static void uwsgi_perl_atexit() {
|
||||
return;
|
||||
|
||||
// managing atexit in async mode is a real pain...skip it for now
|
||||
if (uwsgi.async > 1)
|
||||
if (uwsgi.async > 0)
|
||||
return;
|
||||
realstuff:
|
||||
|
||||
|
||||
@@ -148,7 +148,7 @@ int psgi_response(struct wsgi_request *wsgi_req, AV *response) {
|
||||
chitem = SvPV( chunk, hlen);
|
||||
if (hlen <= 0) {
|
||||
SvREFCNT_dec(chunk);
|
||||
if (uwsgi.async > 1 && wsgi_req->async_force_again) {
|
||||
if (uwsgi.async > 0 && wsgi_req->async_force_again) {
|
||||
wsgi_req->async_placeholder = (SV *) *hitem;
|
||||
return UWSGI_AGAIN;
|
||||
}
|
||||
@@ -161,7 +161,7 @@ int psgi_response(struct wsgi_request *wsgi_req, AV *response) {
|
||||
break;
|
||||
}
|
||||
SvREFCNT_dec(chunk);
|
||||
if (uwsgi.async > 1) {
|
||||
if (uwsgi.async > 0) {
|
||||
wsgi_req->async_placeholder = (SV *) *hitem;
|
||||
wsgi_req->async_force_again = 1;
|
||||
return UWSGI_AGAIN;
|
||||
|
||||
@@ -980,7 +980,7 @@ def uwsgi_pypy_continulet_switch(wsgi_req):
|
||||
lib.uwsgi.wsgi_req = wsgi_req
|
||||
|
||||
def uwsgi_pypy_setup_continulets():
|
||||
if lib.uwsgi.async <= 1:
|
||||
if lib.uwsgi.async < 1:
|
||||
raise Exception("pypy continulets require async mode !!!")
|
||||
lib.uwsgi.schedule_to_main = uwsgi_pypy_continulet_switch
|
||||
lib.uwsgi.schedule_to_req = uwsgi_pypy_continulet_schedule
|
||||
|
||||
@@ -255,7 +255,7 @@ int uwsgi_response_subhandler_pump(struct wsgi_request *wsgi_req) {
|
||||
goto clear;
|
||||
}
|
||||
|
||||
if (uwsgi.async > 1) {
|
||||
if (uwsgi.async > 0) {
|
||||
return UWSGI_AGAIN;
|
||||
}
|
||||
|
||||
|
||||
@@ -361,7 +361,7 @@ void uwsgi_python_atexit() {
|
||||
return;
|
||||
|
||||
// managing atexit in async mode is a real pain...skip it for now
|
||||
if (uwsgi.async > 1)
|
||||
if (uwsgi.async > 0)
|
||||
return;
|
||||
realstuff:
|
||||
|
||||
@@ -1126,7 +1126,7 @@ void uwsgi_python_init_apps() {
|
||||
}
|
||||
|
||||
// prepare for stack suspend/resume
|
||||
if (uwsgi.async > 1) {
|
||||
if (uwsgi.async > 0) {
|
||||
up.current_recursion_depth = uwsgi_malloc(sizeof(int)*uwsgi.async);
|
||||
up.current_frame = uwsgi_malloc(sizeof(struct _frame)*uwsgi.async);
|
||||
}
|
||||
|
||||
@@ -289,7 +289,7 @@ int uwsgi_python_call(struct wsgi_request *wsgi_req, PyObject *callable, PyObjec
|
||||
|
||||
if (wsgi_req->async_result) {
|
||||
while ( manage_python_response(wsgi_req) != UWSGI_OK) {
|
||||
if (uwsgi.async > 1) {
|
||||
if (uwsgi.async > 0) {
|
||||
return UWSGI_AGAIN;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ int uwsgi_request_python_raw(struct wsgi_request *wsgi_req) {
|
||||
int ret = manage_raw_response(wsgi_req);
|
||||
if (ret == UWSGI_AGAIN) {
|
||||
wsgi_req->async_force_again = 1;
|
||||
if (uwsgi.async > 1) {
|
||||
if (uwsgi.async > 0) {
|
||||
UWSGI_RELEASE_GIL return UWSGI_AGAIN;
|
||||
}
|
||||
continue;
|
||||
|
||||
@@ -164,7 +164,7 @@ int uwsgi_response_subhandler_web3(struct wsgi_request *wsgi_req) {
|
||||
if (!wsgi_req->async_placeholder) {
|
||||
goto clear;
|
||||
}
|
||||
if (uwsgi.async > 1) {
|
||||
if (uwsgi.async > 0) {
|
||||
return UWSGI_AGAIN;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -405,7 +405,7 @@ int uwsgi_request_wsgi(struct wsgi_request *wsgi_req) {
|
||||
|
||||
|
||||
while (wi->response_subhandler(wsgi_req) != UWSGI_OK) {
|
||||
if (uwsgi.async > 1) {
|
||||
if (uwsgi.async > 0) {
|
||||
UWSGI_RELEASE_GIL
|
||||
wsgi_req->async_force_again = 1;
|
||||
return UWSGI_AGAIN;
|
||||
|
||||
@@ -170,7 +170,7 @@ void *uwsgi_request_subhandler_wsgi(struct wsgi_request *wsgi_req, struct uwsgi_
|
||||
|
||||
PyDict_SetItemString(wsgi_req->async_environ, "wsgi.file_wrapper", wi->sendfile);
|
||||
|
||||
if (uwsgi.async > 1) {
|
||||
if (uwsgi.async > 0) {
|
||||
PyDict_SetItemString(wsgi_req->async_environ, "x-wsgiorg.fdevent.readable", wi->eventfd_read);
|
||||
PyDict_SetItemString(wsgi_req->async_environ, "x-wsgiorg.fdevent.writable", wi->eventfd_write);
|
||||
PyDict_SetItemString(wsgi_req->async_environ, "x-wsgiorg.fdevent.timeout", Py_None);
|
||||
@@ -269,7 +269,7 @@ int uwsgi_response_subhandler_wsgi(struct wsgi_request *wsgi_req) {
|
||||
if (!wsgi_req->async_placeholder) {
|
||||
goto exception;
|
||||
}
|
||||
if (uwsgi.async > 1) {
|
||||
if (uwsgi.async > 0) {
|
||||
return UWSGI_AGAIN;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ static void uwsgi_rados_read_async_cb(rados_completion_t comp, void *data) {
|
||||
}
|
||||
|
||||
static int uwsgi_rados_delete(struct wsgi_request *wsgi_req, rados_ioctx_t ctx, char *key, int timeout) {
|
||||
if (uwsgi.async <= 1) {
|
||||
if (uwsgi.async < 1) {
|
||||
return rados_remove(ctx, key);
|
||||
}
|
||||
struct uwsgi_rados_io *urio = &urados.urio[wsgi_req->async_id];
|
||||
@@ -147,7 +147,7 @@ static int uwsgi_rados_put(struct wsgi_request *wsgi_req, rados_ioctx_t ctx, cha
|
||||
ssize_t body_len = 0;
|
||||
char *body = uwsgi_request_body_read(wsgi_req, UMIN(remains, 32768) , &body_len);
|
||||
if (!body || body == uwsgi.empty) goto error;
|
||||
if (uwsgi.async <= 1) {
|
||||
if (uwsgi.async < 1) {
|
||||
if (rados_write(ctx, key, body, body_len, off) < 0) {
|
||||
return -1;
|
||||
}
|
||||
@@ -368,7 +368,7 @@ static void uwsgi_rados_propfind(struct wsgi_request *wsgi_req, rados_ioctx_t ct
|
||||
while(rados_objects_list_next(ctx_list, (const char **)&entry, NULL) == 0) {
|
||||
uint64_t stat_size = 0;
|
||||
time_t stat_mtime = 0;
|
||||
if (uwsgi.async > 1) {
|
||||
if (uwsgi.async > 0) {
|
||||
if (uwsgi_rados_async_stat(urio, ctx, entry, &stat_size, &stat_mtime, timeout) < 0) goto end;
|
||||
}
|
||||
else {
|
||||
@@ -513,7 +513,7 @@ static void uwsgi_rados_setup() {
|
||||
}
|
||||
|
||||
// now initialize a pthread_mutex for each async core
|
||||
if (uwsgi.async > 1) {
|
||||
if (uwsgi.async > 0) {
|
||||
int i;
|
||||
urados.urio = uwsgi_calloc(sizeof(struct uwsgi_rados_io) * uwsgi.async);
|
||||
for(i=0;i<uwsgi.async;i++) {
|
||||
@@ -584,7 +584,7 @@ static int uwsgi_rados_request(struct wsgi_request *wsgi_req) {
|
||||
|
||||
struct uwsgi_rados_io *urio = &urados.urio[wsgi_req->async_id];
|
||||
|
||||
if (uwsgi.async > 1) {
|
||||
if (uwsgi.async > 0) {
|
||||
// no need to lock here (the rid protect us)
|
||||
if (pipe(urio->fds)) {
|
||||
uwsgi_error("uwsgi_rados_read_async()/pipe()");
|
||||
@@ -664,7 +664,7 @@ static int uwsgi_rados_request(struct wsgi_request *wsgi_req) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (uwsgi.async > 1) {
|
||||
if (uwsgi.async > 0) {
|
||||
ret = uwsgi_rados_async_stat(urio, ctx, filename, &stat_size, &stat_mtime, timeout);
|
||||
}
|
||||
else {
|
||||
@@ -738,7 +738,7 @@ static int uwsgi_rados_request(struct wsgi_request *wsgi_req) {
|
||||
// skip body on HEAD
|
||||
if (uwsgi_strncmp(wsgi_req->method, wsgi_req->method_len, "HEAD", 4)) {
|
||||
size_t remains = stat_size;
|
||||
if (uwsgi.async > 1) {
|
||||
if (uwsgi.async > 0) {
|
||||
if (uwsgi_rados_read_async(wsgi_req, ctx, filename, remains, timeout)) goto end;
|
||||
}
|
||||
else {
|
||||
@@ -747,7 +747,7 @@ static int uwsgi_rados_request(struct wsgi_request *wsgi_req) {
|
||||
}
|
||||
|
||||
end:
|
||||
if (uwsgi.async > 1) {
|
||||
if (uwsgi.async > 0) {
|
||||
close(urio->fds[0]);
|
||||
close(urio->fds[1]);
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ static void stackless_init_apps(void) {
|
||||
|
||||
if (!usl.enabled) return;
|
||||
|
||||
if (uwsgi.async <= 1) {
|
||||
if (uwsgi.async < 1) {
|
||||
uwsgi_log("the stackless suspend engine requires async mode\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -342,7 +342,7 @@ static void tornado_loop() {
|
||||
|
||||
uwsgi.schedule_fix = uwsgi_tornado_schedule_fix;
|
||||
|
||||
if (uwsgi.async < 2) {
|
||||
if (uwsgi.async < 1) {
|
||||
uwsgi_log("the tornado loop engine requires async mode (--async <n>)\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user