Changeset 767
- Timestamp:
- 05/30/07 22:58:31 (2 years ago)
- Files:
-
- cherokee/trunk/ChangeLog (modified) (1 diff)
- cherokee/trunk/cherokee/connection.c (modified) (11 diffs)
- cherokee/trunk/cherokee/thread.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
cherokee/trunk/ChangeLog
r766 r767 1 2007-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 1 20 2007-05-30 Alvaro Lopez Ortega <alvaro@alobbs.com> 2 21 cherokee/trunk/cherokee/connection.c
r766 r767 595 595 size_t re; 596 596 ret_t ret; 597 int16_t nvec = 1; 597 598 struct iovec bufs[2]; 598 599 … … 617 618 cherokee_connection_tx_add (conn, re); 618 619 619 conn->mmaped_len -= re; 620 /* FIXME: conn->mmaped is a ptr. to void 621 * so ptr. math should be avoided. 622 */ 620 623 conn->mmaped += re; 624 conn->mmaped_len -= (off_t) re; 621 625 622 626 return (conn->mmaped_len <= 0) ? ret_ok : ret_eagain; … … 627 631 bufs[0].iov_base = conn->buffer.buf; 628 632 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); 633 639 634 640 switch (ret) { … … 646 652 default: 647 653 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) 657 673 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; 674 691 } 675 692 … … 712 729 default: 713 730 RET_UNKNOWN(ret); 714 }715 716 return ret_error;731 return ret_error; 732 } 733 /* NOTREACHED */ 717 734 } 718 735 … … 774 791 cherokee_connection_tx_add (conn, sent); 775 792 776 /* Drop out the sent info793 /* Drop out the sent data 777 794 */ 778 795 if (sent == conn->buffer.len) { … … 781 798 } 782 799 783 /* There are still infowaiting to be sent800 /* There is still some data waiting to be sent 784 801 */ 785 802 cherokee_buffer_move_to_begin (&conn->buffer, sent); … … 812 829 ret = ret_eagain; 813 830 } 814 831 815 832 /* If this connection has a handler without content-length support 816 833 * it has to count the bytes sent … … 911 928 default: 912 929 RET_UNKNOWN(step_ret); 930 return step_ret; 913 931 } 914 932 … … 1455 1473 default: 1456 1474 RET_UNKNOWN(ret); 1475 return ret_error; 1457 1476 } 1458 1477 … … 1527 1546 default: 1528 1547 RET_UNKNOWN(ret); 1548 return ret; 1529 1549 } 1530 1550 cherokee/trunk/cherokee/thread.c
r764 r767 211 211 212 212 /* Set upper accept limit to 95% - 99% of conns_max. 213 * TODO: change the following hardcoded limits into a formula. 213 214 */ 214 215 if (conns_max > 40) { … … 634 635 635 636 /* 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. 636 643 */ 637 644 cherokee_server_get_conns_num (srv, &srv_conns_num); … … 765 772 */ 766 773 if (!cherokee_post_got_all (&conn->post)) { 774 srv_conns_num--; 767 775 purge_closed_connection (thd, conn); 768 776 continue; … … 825 833 case ret_eof: 826 834 case ret_error: 835 srv_conns_num--; 827 836 purge_closed_connection (thd, conn); 828 837 continue; 829 838 default: 830 839 RET_UNKNOWN(ret); 840 srv_conns_num--; 831 841 purge_closed_connection (thd, conn); 832 842 continue; … … 853 863 continue; 854 864 case ret_error: 865 srv_conns_num--; 855 866 purge_closed_connection (thd, conn); 856 867 continue; 857 868 default: 858 869 RET_UNKNOWN(ret); 870 srv_conns_num--; 859 871 purge_closed_connection (thd, conn); 860 872 continue; … … 1119 1131 if (ret != ret_ok) { 1120 1132 1121 /* It could not change the handler to an error managing handler,1122 * so it is a critical error1133 /* It could not change the handler to an error 1134 * managing handler, so it is a critical error. 1123 1135 */ 1136 srv_conns_num--; 1124 1137 purge_closed_connection (thd, conn); 1125 1138 continue; … … 1277 1290 case ret_error: 1278 1291 default: 1292 srv_conns_num--; 1279 1293 purge_closed_connection (thd, conn); 1280 1294 /* purge_maybe_lingering (thd, conn); */ … … 1314 1328 * just close the connection. 1315 1329 */ 1330 srv_conns_num--; 1316 1331 purge_closed_connection (thd, conn); 1317 1332 continue; … … 1328 1343 case ret_eof: 1329 1344 case ret_error: 1345 srv_conns_num--; 1330 1346 purge_closed_connection (thd, conn); 1331 1347 continue; 1332 1348 default: 1333 1349 RET_UNKNOWN(ret); 1350 srv_conns_num--; 1334 1351 purge_closed_connection (thd, conn); 1335 1352 break;