Permalink
Browse files

set offload threading stacksize to 512k

  • Loading branch information...
1 parent 0fcb13b commit b2a9fbbc5cdbed1db4d1d5007d4561c2a4e9e291 roberto@goyle committed Apr 17, 2012
Showing with 23 additions and 0 deletions.
  1. +17 −0 protocol.c
  2. +3 −0 uwsgi.c
  3. +3 −0 uwsgi.h
View
@@ -1803,6 +1803,10 @@ void *uwsgi_static_offload_thread(void *req) {
free(uof_req->hvec);
free(uof_req);
+ pthread_mutex_lock(&uwsgi.static_offload_thread_lock);
+ uwsgi.workers[uwsgi.mywid].static_offload_threads--;
+ pthread_mutex_unlock(&uwsgi.static_offload_thread_lock);
+
return NULL;
}
@@ -1853,6 +1857,15 @@ int uwsgi_file_serve(struct wsgi_request *wsgi_req, char *document_root, uint16_
// Ok, the file must be served as static from uWSGI
if (uwsgi.static_offload_to_thread) {
+ pthread_mutex_lock(&uwsgi.static_offload_thread_lock);
+ uint64_t offload_thread_count = uwsgi.workers[uwsgi.mywid].static_offload_threads;
+ pthread_mutex_unlock(&uwsgi.static_offload_thread_lock);
+
+ if (offload_thread_count > (uint64_t) uwsgi.static_offload_to_thread) {
+ uwsgi_log_verbose("OVERLOAD !!! unable to offload static file serving\n");
+ return uwsgi_real_file_serve(wsgi_req, real_filename, real_filename_len, &st);
+ }
+
struct uwsgi_offload_request *uor = uwsgi_malloc(sizeof(struct uwsgi_offload_request));
// buffer
@@ -1876,6 +1889,10 @@ int uwsgi_file_serve(struct wsgi_request *wsgi_req, char *document_root, uint16_
// avoid closing the connection
wsgi_req->fd_closed = 1;
+ pthread_mutex_lock(&uwsgi.static_offload_thread_lock);
+ uwsgi.workers[uwsgi.mywid].static_offload_threads++;
+ pthread_mutex_unlock(&uwsgi.static_offload_thread_lock);
+
if (pthread_create(&uor->tid, &uwsgi.static_offload_thread_attr, uwsgi_static_offload_thread, (void *) uor)) {
uwsgi_error("pthread_create()");
// bad condition, better to exit...
View
@@ -1869,6 +1869,9 @@ int uwsgi_start(void *v_argv) {
if (uwsgi.static_offload_to_thread) {
pthread_attr_init(&uwsgi.static_offload_thread_attr);
pthread_attr_setdetachstate(&uwsgi.static_offload_thread_attr, PTHREAD_CREATE_DETACHED);
+ // 512K should be enough...
+ pthread_attr_setstacksize(&uwsgi.static_offload_thread_attr, 512*1024);
+ pthread_mutex_init(&uwsgi.static_offload_thread_lock, NULL);
}
// end of generic initialization
View
@@ -1282,6 +1282,7 @@ struct uwsgi_server {
int check_static_docroot;
int static_offload_to_thread;
pthread_attr_t static_offload_thread_attr;
+ pthread_mutex_t static_offload_thread_lock;
char *daemonize;
char *daemonize2;
@@ -1873,6 +1874,8 @@ struct uwsgi_worker {
uint64_t avg_response_time;
+ uint64_t static_offload_threads;
+
char name[0xff];
};

0 comments on commit b2a9fbb

Please sign in to comment.