Changeset 767

Show
Ignore:
Timestamp:
05/30/07 22:58:31 (2 years ago)
Author:
alo
Message:

--

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • cherokee/trunk/ChangeLog

    r766 r767  
     12007-05-30  A.D.F  <adefacc@tin.it> 
     2 
     3        * cherokee/connection.c: 
     4        - added a few return(s) after RET_UNKNOWN() 
     5          because it is only a debug print (it does no return); 
     6        - cherokee_connection_send*(): 
     7          - reworked code after cherokee_socket_writev() 
     8            in order to speedup things for small writes; 
     9          - added a couple of FIXME (to avoid ptr. void math). 
     10 
     11        * cherokee/thread.c: 
     12        - cherokee_thread_new: 
     13          - added a comment to replace hardcoded numbers 
     14            with a formula; 
     15 
     16        - process_active_connections(), 
     17          - added a few decrease of private connection counter 
     18            before each purge_closed_connection(). 
     19         
    1202007-05-30  Alvaro Lopez Ortega  <alvaro@alobbs.com> 
    221 
  • cherokee/trunk/cherokee/connection.c

    r766 r767  
    595595        size_t  re; 
    596596        ret_t   ret; 
     597        int16_t nvec = 1; 
    597598        struct iovec bufs[2]; 
    598599 
     
    617618                cherokee_connection_tx_add (conn, re); 
    618619 
    619                 conn->mmaped_len -= re; 
     620                /* FIXME: conn->mmaped is a ptr. to void 
     621                 * so ptr. math should be avoided. 
     622                 */ 
    620623                conn->mmaped     += re; 
     624                conn->mmaped_len -= (off_t) re; 
    621625 
    622626                return (conn->mmaped_len <= 0) ? ret_ok : ret_eagain; 
     
    627631        bufs[0].iov_base = conn->buffer.buf; 
    628632        bufs[0].iov_len  = conn->buffer.len; 
    629         bufs[1].iov_base = conn->mmaped; 
    630         bufs[1].iov_len  = conn->mmaped_len; 
    631  
    632         ret = cherokee_socket_writev (&conn->socket, bufs, 2, &re); 
     633        if (likely( conn->mmaped_len > 0 )) { 
     634                bufs[1].iov_base = conn->mmaped; 
     635                bufs[1].iov_len  = conn->mmaped_len; 
     636                nvec = 2; 
     637        } 
     638        ret = cherokee_socket_writev (&conn->socket, bufs, nvec, &re); 
    633639 
    634640        switch (ret) { 
     
    646652        default: 
    647653                RET_UNKNOWN(ret); 
    648         } 
    649          
    650         /* If writev() has not sent all data 
    651          */ 
    652         if (re < conn->buffer.len + conn->mmaped_len) { 
    653                 int offset; 
    654  
    655                 if (re <= conn->buffer.len) { 
    656                         cherokee_buffer_move_to_begin (&conn->buffer, re); 
     654                return ret_error; 
     655        } 
     656 
     657        /* Add to the connection traffic counter 
     658         */ 
     659        cherokee_connection_tx_add (conn, re); 
     660 
     661        /* If writev() has sent all data.  
     662         */ 
     663        if (re == (size_t) (conn->buffer.len + conn->mmaped_len)) { 
     664                cherokee_buffer_clean (&conn->buffer); 
     665                return ret_ok; 
     666        } 
     667 
     668        /* writev() may not have sent all data. 
     669         */ 
     670        if (re <= (size_t) conn->buffer.len) { 
     671                cherokee_buffer_move_to_begin (&conn->buffer, re); 
     672                if (conn->mmaped_len > 0) 
    657673                        return ret_eagain; 
    658                 } 
    659                  
    660                 offset = re - conn->buffer.len; 
    661                 conn->mmaped     += offset; 
    662                 conn->mmaped_len -= offset; 
    663  
    664                 cherokee_buffer_clean (&conn->buffer); 
    665  
    666                 return ret_eagain; 
    667         } 
    668  
    669         /* Add to the connection traffic counter 
    670          */ 
    671         cherokee_connection_tx_add (conn, re); 
    672  
    673         return ret_ok; 
     674                return ret_ok; 
     675        } 
     676 
     677        /* writev() has not sent all data: 
     678         * re > conn->buffer.len && conn->mmaped_len > 0; 
     679         */ 
     680        re -= (size_t) conn->buffer.len; 
     681 
     682        /* FIXME: conn->mmaped is a ptr. to void 
     683         * so ptr. math should be avoided. 
     684         */ 
     685        conn->mmaped     += re; 
     686        conn->mmaped_len -= (off_t) re; 
     687 
     688        cherokee_buffer_clean (&conn->buffer); 
     689 
     690        return ret_eagain; 
    674691} 
    675692 
     
    712729        default: 
    713730                RET_UNKNOWN(ret);                
    714         } 
    715  
    716         return ret_error; 
     731               return ret_error; 
     732        } 
     733        /* NOTREACHED */ 
    717734} 
    718735 
     
    774791        cherokee_connection_tx_add (conn, sent); 
    775792 
    776         /* Drop out the sent info 
     793        /* Drop out the sent data 
    777794         */ 
    778795        if (sent == conn->buffer.len) { 
     
    781798        } 
    782799 
    783         /* There are still info waiting to be sent 
     800        /* There is still some data waiting to be sent 
    784801         */ 
    785802        cherokee_buffer_move_to_begin (&conn->buffer, sent); 
     
    812829                ret = ret_eagain; 
    813830        } 
    814          
     831 
    815832        /* If this connection has a handler without content-length support 
    816833         * it has to count the bytes sent 
     
    911928        default: 
    912929                RET_UNKNOWN(step_ret); 
     930                return step_ret; 
    913931        } 
    914932 
     
    14551473        default: 
    14561474                RET_UNKNOWN(ret); 
     1475                return ret_error; 
    14571476        } 
    14581477 
     
    15271546        default: 
    15281547                RET_UNKNOWN(ret); 
     1548                return ret; 
    15291549        } 
    15301550 
  • cherokee/trunk/cherokee/thread.c

    r764 r767  
    211211 
    212212        /* Set upper accept limit to 95% - 99% of conns_max. 
     213         * TODO: change the following hardcoded limits into a formula. 
    213214         */ 
    214215        if (conns_max > 40) { 
     
    634635 
    635636        /* Get total connection count. 
     637         * NOTE: when there are 2 or more threads, 
     638         *       the real connection count can change while this thread 
     639         *       is processing connections;  as taking and releasing 
     640         *       a lock might slow down things, we keep a private 
     641         *       counter (srv_conns_num) that we decrease on every 
     642         *       connection close; this should be enough for now. 
    636643         */ 
    637644        cherokee_server_get_conns_num (srv, &srv_conns_num); 
     
    765772                                 */ 
    766773                                if (!cherokee_post_got_all (&conn->post)) { 
     774                                        srv_conns_num--; 
    767775                                        purge_closed_connection (thd, conn); 
    768776                                        continue; 
     
    825833                        case ret_eof: 
    826834                        case ret_error: 
     835                                srv_conns_num--; 
    827836                                purge_closed_connection (thd, conn); 
    828837                                continue; 
    829838                        default: 
    830839                                RET_UNKNOWN(ret); 
     840                                srv_conns_num--; 
    831841                                purge_closed_connection (thd, conn); 
    832842                                continue; 
     
    853863                                continue; 
    854864                        case ret_error: 
     865                                srv_conns_num--; 
    855866                                purge_closed_connection (thd, conn); 
    856867                                continue; 
    857868                        default: 
    858869                                RET_UNKNOWN(ret); 
     870                                srv_conns_num--; 
    859871                                purge_closed_connection (thd, conn); 
    860872                                continue; 
     
    11191131                                if (ret != ret_ok) { 
    11201132                                         
    1121                                         /* It could not change the handler to an error managing handler, 
    1122                                          * so it is a critical error 
     1133                                        /* It could not change the handler to an error 
     1134                                         * managing handler, so it is a critical error. 
    11231135                                         */                                      
     1136                                        srv_conns_num--; 
    11241137                                        purge_closed_connection (thd, conn); 
    11251138                                        continue; 
     
    12771290                                case ret_error: 
    12781291                                default: 
     1292                                        srv_conns_num--; 
    12791293                                        purge_closed_connection (thd, conn); 
    12801294                                        /* purge_maybe_lingering (thd, conn); */ 
     
    13141328                                 * just close the connection. 
    13151329                                 */ 
     1330                                srv_conns_num--; 
    13161331                                purge_closed_connection (thd, conn); 
    13171332                                continue; 
     
    13281343                        case ret_eof: 
    13291344                        case ret_error: 
     1345                                srv_conns_num--; 
    13301346                                purge_closed_connection (thd, conn); 
    13311347                                continue; 
    13321348                        default: 
    13331349                                RET_UNKNOWN(ret); 
     1350                                srv_conns_num--; 
    13341351                                purge_closed_connection (thd, conn); 
    13351352                                break;