Changeset a0b8bf
- Timestamp:
- 03/05/08 19:16:07 (4 years ago)
- Branches:
- master, ketama-compat
- Children:
- 787337
- Parents:
- cc8dfa
- git-author:
- Tomash Brechko <tomash.brechko@…> (03/05/08 19:16:07)
- git-committer:
- Tomash Brechko <tomash.brechko@…> (03/05/08 19:16:07)
- File:
-
- 1 edited
-
src/client.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/client.c
ra57c5d ra0b8bf 39 39 #include <signal.h> 40 40 #include <time.h> 41 #include <netinet/in.h> 42 #include <netinet/tcp.h> 41 43 42 44 … … 94 96 95 97 98 enum socket_mode_e { NOT_TCP = -1, TCP_LATENCY, TCP_THROUGHPUT }; 99 100 96 101 struct client; 97 102 … … 101 106 struct client *client; 102 107 int fd; 108 enum socket_mode_e socket_mode; 103 109 int noreply; 104 110 int last_cmd_noreply; … … 1519 1525 1520 1526 1527 /* Is the following required for any platform? */ 1528 #if (! defined(IPPROTO_TCP) && defined(SOL_TCP)) 1529 #define IPPROTO_TCP SOL_TCP 1530 #endif 1531 1532 1533 static inline 1534 void 1535 tcp_optimize_latency(struct command_state *state) 1536 { 1537 #ifdef TCP_NODELAY 1538 if (state->socket_mode == TCP_THROUGHPUT) 1539 { 1540 static const int enable = 1; 1541 setsockopt(state->fd, IPPROTO_TCP, TCP_NODELAY, 1542 &enable, sizeof(enable)); 1543 state->socket_mode = TCP_LATENCY; 1544 } 1545 #endif /* TCP_NODELAY */ 1546 } 1547 1548 1549 static inline 1550 void 1551 tcp_optimize_throughput(struct command_state *state) 1552 { 1553 #ifdef TCP_NODELAY 1554 if (state->socket_mode == TCP_LATENCY) 1555 { 1556 static const int disable = 0; 1557 setsockopt(state->fd, IPPROTO_TCP, TCP_NODELAY, 1558 &disable, sizeof(disable)); 1559 state->socket_mode = TCP_THROUGHPUT; 1560 } 1561 #endif /* TCP_NODELAY */ 1562 } 1563 1564 1521 1565 static 1522 1566 int … … 1544 1588 state->fd = client_connect_inet(s->host, s->port, 1545 1589 1, c->connect_timeout); 1590 /* This is to trigger actual reset. */ 1591 state->socket_mode = TCP_THROUGHPUT; 1592 tcp_optimize_latency(state); 1546 1593 } 1547 1594 else 1548 1595 { 1549 1596 state->fd = client_connect_unix(s->host, s->host_len); 1597 state->socket_mode = NOT_TCP; 1550 1598 } 1551 1599 } … … 1609 1657 { 1610 1658 if (state->client->nowait || state->noreply) 1611 parse_reply = NULL; 1659 { 1660 parse_reply = NULL; 1661 tcp_optimize_throughput(state); 1662 } 1612 1663 1613 1664 state->last_cmd_noreply = state->noreply; … … 1616 1667 { 1617 1668 state->last_cmd_noreply = 0; 1669 tcp_optimize_latency(state); 1618 1670 } 1619 1671 … … 2008 2060 --state->nowait_count; 2009 2061 command_state_reset(state, 0, parse_nowait_reply); 2062 tcp_optimize_latency(state); 2010 2063 ++state->reply_count; 2011 2064 }
Note: See TracChangeset
for help on using the changeset viewer.
