Permalink
Browse files

Merge remote branch 'upstream/master'

  • Loading branch information...
git001 committed Apr 14, 2012
2 parents bf6b07a + 02256c0 commit 6275cefc7bf156016faf29ee59b64a86f77648f0
View
@@ -49,3 +49,4 @@ af490b8c30f83bc5fb6f3837a760981474647755 1.0-rc10
ede5c664978bb40e476e8d4a5789562928f28507 1.1-rc3
ef99144291f06822d026e981d5d856cbec14d867 1.1-rc4
e1568fd16b7b586cc72deb4dfccbbe64ae0b84df 1.1
+24c8fe5a26e557db41cf1cee45b8964d5885e484 1.2-rc1
View
43 lock.c
@@ -118,6 +118,27 @@ pid_t uwsgi_rwlock_fast_check(struct uwsgi_lock_item *uli) {
#endif
}
+
+void uwsgi_lock_fast(struct uwsgi_lock_item *uli) {
+
+#ifdef EOWNERDEAD
+ if (pthread_mutex_lock((pthread_mutex_t *) uli->lock_ptr) == EOWNERDEAD) {
+ uwsgi_log("[deadlock-detector] a process holding a robust mutex died. recovering...\n");
+ pthread_mutex_consistent_np((pthread_mutex_t *) uli->lock_ptr);
+ }
+#else
+ pthread_mutex_lock((pthread_mutex_t *) uli->lock_ptr);
+#endif
+ uli->pid = uwsgi.mypid;
+}
+
+void uwsgi_unlock_fast(struct uwsgi_lock_item *uli) {
+
+ pthread_mutex_unlock((pthread_mutex_t *) uli->lock_ptr);
+ uli->pid = 0;
+
+}
+
void uwsgi_rlock_fast(struct uwsgi_lock_item *uli) {
#ifdef OBSOLETE_LINUX_KERNEL
uwsgi_lock_fast(uli);
@@ -145,30 +166,10 @@ void uwsgi_rwunlock_fast(struct uwsgi_lock_item *uli) {
#endif
}
-void uwsgi_lock_fast(struct uwsgi_lock_item *uli) {
-
-#ifdef EOWNERDEAD
- if (pthread_mutex_lock((pthread_mutex_t *) uli->lock_ptr) == EOWNERDEAD) {
- uwsgi_log("[deadlock-detector] a process holding a robust mutex died. recovering...\n");
- pthread_mutex_consistent_np((pthread_mutex_t *) uli->lock_ptr);
- }
-#else
- pthread_mutex_lock((pthread_mutex_t *) uli->lock_ptr);
-#endif
- uli->pid = uwsgi.mypid;
-}
-
-void uwsgi_unlock_fast(struct uwsgi_lock_item *uli) {
-
- pthread_mutex_unlock((pthread_mutex_t *) uli->lock_ptr);
- uli->pid = 0;
-
-}
-
struct uwsgi_lock_item *uwsgi_rwlock_fast_init(char *id) {
#ifdef OBSOLETE_LINUX_KERNEL
- return uwsgi_lock_fast_init(uli);
+ return uwsgi_lock_fast_init(id);
#else
pthread_rwlockattr_t attr;
View
@@ -160,7 +160,11 @@ void log_request(struct wsgi_request *wsgi_req) {
via = msg3;
}
+#ifdef __sun__
+ ctime_r((const time_t *) &wsgi_req->start_of_request.tv_sec, time_request, 26);
+#else
ctime_r((const time_t *) &wsgi_req->start_of_request.tv_sec, time_request);
+#endif
microseconds = wsgi_req->end_of_request.tv_sec * 1000000 + wsgi_req->end_of_request.tv_usec;
microseconds2 = wsgi_req->start_of_request.tv_sec * 1000000 + wsgi_req->start_of_request.tv_usec;
View
@@ -140,6 +140,7 @@ void *cache_sweeper_loop(void *noarg) {
}
};
+ return NULL;
}
void uwsgi_subscribe(char *subscription, uint8_t cmd) {
View
@@ -7,13 +7,15 @@ struct uwsgi_carbon {
int freq;
int timeout;
char *id;
+ int no_workers;
} u_carbon;
struct uwsgi_option carbon_options[] = {
{"carbon", required_argument, 0, "push statistics to the specified carbon server", uwsgi_opt_add_string_list, &u_carbon.servers, UWSGI_OPT_MASTER},
{"carbon-timeout", required_argument, 0, "set carbon connection timeout", uwsgi_opt_set_int, &u_carbon.timeout, 0},
{"carbon-freq", required_argument, 0, "set carbon push frequency", uwsgi_opt_set_int, &u_carbon.freq, 0},
{"carbon-id", required_argument, 0, "set carbon id", uwsgi_opt_set_str, &u_carbon.id, 0},
+ {"carbon-no-workers", no_argument, 0, "disable generation of single worker metrics", uwsgi_opt_true, &u_carbon.no_workers, 0},
{0, 0, 0, 0, 0, 0, 0},
};
@@ -73,6 +75,8 @@ void carbon_master_cycle() {
rlen = snprintf(ptr, 4096, "uwsgi.%s.%s.requests %llu %llu\n", uwsgi.hostname, u_carbon.id, (unsigned long long ) uwsgi.workers[0].requests, (unsigned long long ) uwsgi.current_time);
if (rlen < 1) goto clear;
if (write(fd, ptr, rlen) <= 0) { uwsgi_error("write()"); goto clear;}
+
+ if (u_carbon.no_workers) goto gmetrics;
for(i=1;i<=uwsgi.numproc;i++) {
rlen = snprintf(ptr, 4096, "uwsgi.%s.%s.worker%d.requests %llu %llu\n", uwsgi.hostname, u_carbon.id, i, (unsigned long long ) uwsgi.workers[i].requests, (unsigned long long ) uwsgi.current_time);
@@ -109,6 +113,8 @@ void carbon_master_cycle() {
if (write(fd, ptr, rlen) <= 0) { uwsgi_error("write()"); goto clear;}
}
+gmetrics:
+
rlen = snprintf(ptr, 4096, "uwsgi.%s.%s.rss_size %llu %llu\n", uwsgi.hostname, u_carbon.id, (unsigned long long ) total_rss, (unsigned long long ) uwsgi.current_time);
if (rlen < 1) goto clear;
if (write(fd, ptr, rlen) <= 0) { uwsgi_error("write()"); goto clear;}
View
@@ -94,12 +94,11 @@ static int sapi_uwsgi_ub_write(const char *str, uint str_length TSRMLS_DC)
{
struct wsgi_request *wsgi_req = (struct wsgi_request *) SG(server_context);
- ssize_t len = wsgi_req->socket->proto_write(wsgi_req, (char *) str, str_length);
- if (len != (ssize_t) str_length) {
+ wsgi_req->response_size += wsgi_req->socket->proto_write(wsgi_req, (char *) str, str_length);
+ if (wsgi_req->write_errors > uwsgi.write_errors_tolerance) {
php_handle_aborted_connection();
return -1;
}
- wsgi_req->response_size += len;
return str_length;
}
@@ -126,9 +126,7 @@ int psgi_response(struct wsgi_request *wsgi_req, AV *response) {
vi = (i*2)+base;
wsgi_req->hvec[vi].iov_base = "\r\n"; wsgi_req->hvec[vi].iov_len = 2;
- if ( !(wsgi_req->headers_size += wsgi_req->socket->proto_writev_header(wsgi_req, wsgi_req->hvec, vi+1)) ) {
- uwsgi_error("writev()");
- }
+ wsgi_req->headers_size += wsgi_req->socket->proto_writev_header(wsgi_req, wsgi_req->hvec, vi+1);
hitem = av_fetch(response, 2, 0);
@@ -124,6 +124,7 @@ struct uwsgi_option uwsgi_python_options[] = {
{"py-autoreload", required_argument, 0, "monitor python modules mtime to trigger reload (use only in development)", uwsgi_opt_set_int, &up.auto_reload, UWSGI_OPT_THREADS|UWSGI_OPT_MASTER},
{"python-auto-reload", required_argument, 0, "monitor python modules mtime to trigger reload (use only in development)", uwsgi_opt_set_int, &up.auto_reload, UWSGI_OPT_THREADS|UWSGI_OPT_MASTER},
{"python-autoreload", required_argument, 0, "monitor python modules mtime to trigger reload (use only in development)", uwsgi_opt_set_int, &up.auto_reload, UWSGI_OPT_THREADS|UWSGI_OPT_MASTER},
+ {"py-auto-reload-ignore", required_argument, 0, "ignore the specified module during auto-reload scan (can be specified multiple times)", uwsgi_opt_add_string_list, &up.auto_reload_ignore, UWSGI_OPT_THREADS|UWSGI_OPT_MASTER},
#endif
{0, 0, 0, 0, 0, 0, 0},
@@ -552,6 +553,7 @@ void init_uwsgi_embedded_module() {
// just for safety
Py_INCREF(up.embedded_dict);
+
if (PyDict_SetItemString(up.embedded_dict, "version", PyString_FromString(UWSGI_VERSION))) {
PyErr_Print();
exit(1);
@@ -1280,6 +1282,16 @@ void *uwsgi_python_autoreloader_thread(void *foobar) {
#endif
PyObject *mod_name, *mod;
while (PyDict_Next(modules, &pos, &mod_name, &mod)) {
+ int found = 0;
+ struct uwsgi_string_list *usl = up.auto_reload_ignore;
+ while(usl) {
+ if (!strcmp(usl->value, PyString_AsString(mod_name))) {
+ found = 1;
+ break;
+ }
+ usl = usl->next;
+ }
+ if (found) continue;
if (!PyObject_HasAttrString(mod, "__file__")) continue;
PyObject *mod_file = PyObject_GetAttrString(mod, "__file__");
if (!mod_file) continue;
@@ -38,6 +38,14 @@
#define PyVarObject_HEAD_INIT(x, y) PyObject_HEAD_INIT(x) y,
#endif
+#define uwsgi_py_write_set_exception(x) PyErr_SetString(PyExc_IOError, "write error");
+#define uwsgi_py_write_exception(x) uwsgi_py_write_set_exception(x); PyErr_Print();
+
+
+#define uwsgi_py_check_write_errors if (wsgi_req->write_errors > 0 && uwsgi.write_errors_exception_only) {\
+ uwsgi_py_write_set_exception(wsgi_req);\
+ }\
+ else if (wsgi_req->write_errors > uwsgi.write_errors_tolerance)\
PyAPI_FUNC(PyObject *) PyMarshal_WriteObjectToString(PyObject *, int);
PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromString(char *, Py_ssize_t);
@@ -152,6 +160,7 @@ struct uwsgi_python {
void (*gil_get) (void);
void (*gil_release) (void);
int auto_reload;
+ struct uwsgi_string_list *auto_reload_ignore;
#endif
PyObject *workers_tuple;
@@ -134,7 +134,6 @@ void *uwsgi_request_subhandler_web3(struct wsgi_request *wsgi_req, struct uwsgi_
int uwsgi_response_subhandler_web3(struct wsgi_request *wsgi_req) {
PyObject *pychunk;
- ssize_t wsize;
// ok its a yield
if (!wsgi_req->async_placeholder) {
@@ -168,11 +167,14 @@ int uwsgi_response_subhandler_web3(struct wsgi_request *wsgi_req) {
Py_DECREF(spit_args);
if (PyString_Check((PyObject *)wsgi_req->async_placeholder)) {
- if ((wsize = wsgi_req->socket->proto_write(wsgi_req, PyString_AsString(wsgi_req->async_placeholder), PyString_Size(wsgi_req->async_placeholder))) < 0) {
- uwsgi_error("write()");
- goto clear;
+ char *content = PyString_AsString(wsgi_req->async_placeholder);
+ size_t content_len = PyString_Size(wsgi_req->async_placeholder);
+ UWSGI_RELEASE_GIL
+ wsgi_req->response_size += wsgi_req->socket->proto_write(wsgi_req, content, content_len);
+ UWSGI_GET_GIL
+ uwsgi_py_check_write_errors {
+ uwsgi_py_write_exception(wsgi_req);
}
- wsgi_req->response_size += wsize;
goto clear;
}
@@ -208,12 +210,16 @@ int uwsgi_response_subhandler_web3(struct wsgi_request *wsgi_req) {
if (PyString_Check(pychunk)) {
- if ((wsize = wsgi_req->socket->proto_write(wsgi_req, PyString_AsString(pychunk), PyString_Size(pychunk))) < 0) {
- uwsgi_error("write()");
+ char *content = PyString_AsString(pychunk);
+ size_t content_len = PyString_Size(pychunk);
+ UWSGI_RELEASE_GIL
+ wsgi_req->response_size += wsgi_req->socket->proto_write(wsgi_req, content, content_len);
+ UWSGI_GET_GIL
+ uwsgi_py_check_write_errors {
+ uwsgi_py_write_exception(wsgi_req);
Py_DECREF(pychunk);
goto clear;
}
- wsgi_req->response_size += wsize;
}
@@ -278,6 +278,12 @@ PyObject *py_uwsgi_write(PyObject * self, PyObject * args) {
UWSGI_RELEASE_GIL
wsgi_req->response_size = wsgi_req->socket->proto_write(wsgi_req, content, len);
UWSGI_GET_GIL
+ // this is a special case for the write callable
+ // no need to honout write-errors-exception-only
+ if (wsgi_req->write_errors > uwsgi.write_errors_tolerance) {
+ uwsgi_py_write_set_exception(wsgi_req);
+ return NULL;
+ }
}
Py_INCREF(Py_None);
@@ -201,6 +201,11 @@ PyObject *py_uwsgi_spit(PyObject * self, PyObject * args) {
UWSGI_GET_GIL
#endif
+ if (wsgi_req->write_errors > uwsgi.write_errors_tolerance) {
+ uwsgi_py_write_set_exception(wsgi_req);
+ return NULL;
+ }
+
//uwsgi_log("%d %p\n", wsgi_req->poll.fd, up.wsgi_writeout);
Py_INCREF(up.wsgi_writeout);
@@ -158,18 +158,20 @@ void *uwsgi_request_subhandler_wsgi(struct wsgi_request *wsgi_req, struct uwsgi_
int uwsgi_response_subhandler_wsgi(struct wsgi_request *wsgi_req) {
PyObject *pychunk;
- ssize_t wsize;
#ifdef UWSGI_SENDFILE
ssize_t sf_len = 0;
#endif
// return or yield ?
if (PyString_Check((PyObject *)wsgi_req->async_result)) {
- if ((wsize = wsgi_req->socket->proto_write(wsgi_req, PyString_AsString(wsgi_req->async_result), PyString_Size(wsgi_req->async_result))) < 0) {
- uwsgi_error("write()");
- goto clear;
+ char *content = PyString_AsString(wsgi_req->async_result);
+ size_t content_len = PyString_Size(wsgi_req->async_result);
+ UWSGI_RELEASE_GIL
+ wsgi_req->response_size += wsgi_req->socket->proto_write(wsgi_req, content, content_len);
+ UWSGI_GET_GIL
+ uwsgi_py_check_write_errors {
+ uwsgi_py_write_exception(wsgi_req);
}
- wsgi_req->response_size += wsize;
goto clear;
}
@@ -248,12 +250,16 @@ int uwsgi_response_subhandler_wsgi(struct wsgi_request *wsgi_req) {
if (PyString_Check(pychunk)) {
- if ((wsize = wsgi_req->socket->proto_write(wsgi_req, PyString_AsString(pychunk), PyString_Size(pychunk))) < 0) {
- uwsgi_error("write()");
+ char *content = PyString_AsString(pychunk);
+ size_t content_len = PyString_Size(pychunk);
+ UWSGI_RELEASE_GIL
+ wsgi_req->response_size += wsgi_req->socket->proto_write(wsgi_req, content, content_len);
+ UWSGI_GET_GIL
+ uwsgi_py_check_write_errors {
+ uwsgi_py_write_exception(wsgi_req);
Py_DECREF(pychunk);
goto clear;
}
- wsgi_req->response_size += wsize;
}
#ifdef UWSGI_SENDFILE
View
@@ -520,18 +520,15 @@ VALUE call_dispatch(VALUE env) {
static VALUE send_body(VALUE obj) {
struct wsgi_request *wsgi_req = current_wsgi_req();
- ssize_t len = 0;
//uwsgi_log("sending body\n");
if (TYPE(obj) == T_STRING) {
- len = wsgi_req->socket->proto_write( wsgi_req, RSTRING_PTR(obj), RSTRING_LEN(obj));
+ wsgi_req->response_size += wsgi_req->socket->proto_write( wsgi_req, RSTRING_PTR(obj), RSTRING_LEN(obj));
}
else {
uwsgi_log("UNMANAGED BODY TYPE %d\n", TYPE(obj));
}
- wsgi_req->response_size += len;
-
return Qnil;
}
@@ -765,9 +762,7 @@ int uwsgi_rack_request(struct wsgi_request *wsgi_req) {
wsgi_req->hvec[5].iov_base = (char *) "\r\n";
wsgi_req->hvec[5].iov_len = 2 ;
- if ( !(wsgi_req->headers_size = wsgi_req->socket->proto_writev_header(wsgi_req, wsgi_req->hvec, 6)) ) {
- uwsgi_error("writev()");
- }
+ wsgi_req->headers_size = wsgi_req->socket->proto_writev_header(wsgi_req, wsgi_req->hvec, 6);
headers = RARRAY_PTR(ret)[1] ;
if (rb_respond_to( headers, rb_intern("each") )) {
@@ -778,9 +773,7 @@ int uwsgi_rack_request(struct wsgi_request *wsgi_req) {
}
}
- if (wsgi_req->socket->proto_write(wsgi_req, (char *)"\r\n", 2) != 2) {
- uwsgi_error("write()");
- }
+ wsgi_req->socket->proto_write(wsgi_req, (char *)"\r\n", 2);
body = RARRAY_PTR(ret)[2] ;
@@ -56,7 +56,11 @@ ssize_t uwsgi_rsyslog_logger(struct uwsgi_logger *ul, char *message, size_t len)
// drop newline
if (message[len-1] == '\n') len--;
+#ifdef __sun__
+ ctime_r(&current_time, ctime_storage, 26);
+#else
ctime_r(&current_time, ctime_storage);
+#endif
rlen = snprintf(buf, MAX_SYSLOG_PKT, "<29>%.*s %s: %.*s", 15, ctime_storage+4, (char *) ul->data, (int) len, message);
if (rlen > 0) {
return sendto(ul->fd, buf, rlen, 0, (const struct sockaddr *) &ul->addr, ul->addr_len);
@@ -12,10 +12,14 @@ struct uwsgi_syslog_facility {
struct uwsgi_syslog_facility usf[] = {
{ "auth", LOG_AUTH, },
+#ifdef LOG_AUTHPRIV
{ "authpriv", LOG_AUTHPRIV, },
+#endif
{ "cron", LOG_CRON, },
{ "daemon", LOG_DAEMON, },
+#ifdef LOG_FTP
{ "ftp", LOG_FTP, },
+#endif
#ifdef LOG_INSTALL
{ "install", LOG_INSTALL },
#endif
Oops, something went wrong.

0 comments on commit 6275cef

Please sign in to comment.