set offload threading stacksize to 512k

This commit is contained in:
roberto@goyle
2012-04-17 22:26:32 +02:00
parent 0fcb13b9f1
commit b2a9fbbc5c
3 changed files with 23 additions and 0 deletions
+17
View File
@@ -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...
+3
View File
@@ -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
+3
View File
@@ -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];
};