Changeset a0b8bf


Ignore:
Timestamp:
03/05/08 19:16:07 (4 years ago)
Author:
Tomash Brechko <tomash.brechko@…>
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)
Message:

Control latency-throughput with TCP_NODELAY.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/client.c

    ra57c5d ra0b8bf  
    3939#include <signal.h> 
    4040#include <time.h> 
     41#include <netinet/in.h> 
     42#include <netinet/tcp.h> 
    4143 
    4244 
     
    9496 
    9597 
     98enum socket_mode_e { NOT_TCP = -1, TCP_LATENCY, TCP_THROUGHPUT }; 
     99 
     100 
    96101struct client; 
    97102 
     
    101106  struct client *client; 
    102107  int fd; 
     108  enum socket_mode_e socket_mode; 
    103109  int noreply; 
    104110  int last_cmd_noreply; 
     
    15191525 
    15201526 
     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 
     1533static inline 
     1534void 
     1535tcp_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 
     1549static inline 
     1550void 
     1551tcp_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 
    15211565static 
    15221566int 
     
    15441588          state->fd = client_connect_inet(s->host, s->port, 
    15451589                                          1, c->connect_timeout); 
     1590          /* This is to trigger actual reset.  */ 
     1591          state->socket_mode = TCP_THROUGHPUT; 
     1592          tcp_optimize_latency(state); 
    15461593        } 
    15471594      else 
    15481595        { 
    15491596          state->fd = client_connect_unix(s->host, s->host_len); 
     1597          state->socket_mode = NOT_TCP; 
    15501598        } 
    15511599    } 
     
    16091657        { 
    16101658          if (state->client->nowait || state->noreply) 
    1611             parse_reply = NULL; 
     1659            { 
     1660              parse_reply = NULL; 
     1661              tcp_optimize_throughput(state); 
     1662            } 
    16121663 
    16131664          state->last_cmd_noreply = state->noreply; 
     
    16161667        { 
    16171668          state->last_cmd_noreply = 0; 
     1669          tcp_optimize_latency(state); 
    16181670        } 
    16191671 
     
    20082060      --state->nowait_count; 
    20092061      command_state_reset(state, 0, parse_nowait_reply); 
     2062      tcp_optimize_latency(state); 
    20102063      ++state->reply_count; 
    20112064    } 
Note: See TracChangeset for help on using the changeset viewer.