Significance of Redis 4.0.7 networking.c writeToClient(...) function avoiding send more than NET_MAX_WRITES_PER_EVENT

5 views
Skip to first unread message

Frank Chang

unread,
Jan 31, 2018, 8:12:38 PM1/31/18
to Redis DB
   What is the significance of the Redis 4.0.7 networking.c writeToClient(...) function avoiding send more than NET_MAX_WRITES_PER_EVENT?

   In Redis 4.0.7 networking.c , there is a "C" function with the signature  int writeToClient(int fd, client *c, int handler_installed)

   /* Write data in output buffers to client. Return C_OK if the client
    * is still valid after the call, C_ERR if it was freed. */
  int writeToClient(int fd, client *c, int handler_installed) {

   which has the C-style comment before line 947 of networking.c

  /* Note that we avoid to send more than NET_MAX_WRITES_PER_EVENT
         * bytes, in a single threaded server it's a good idea to serve
         * other clients as well, even if a very large request comes from
         * super fast link that is always able to accept data (in real world
         * scenario think about 'KEYS *' against the loopback interface).
         *
         * However if we are over the maxmemory limit we ignore that and
         * just deliver as much data as it is possible to deliver.
         *
         * Moreover, we also send as much as possible if the client is
         * a slave (otherwise, on high-speed traffic, the replication
         * buffer will grow indefinitely) */
        if (totwritten > NET_MAX_WRITES_PER_EVENT &&
            (server.maxmemory == 0 ||
             zmalloc_used_memory() < server.maxmemory) &&
            !(c->flags & CLIENT_SLAVE)) break;

    We are testing the Redis 4.0.7 Publish and Subscribe architecture with very fast realtime data streams.
    Thank you.

Reply all
Reply to author
Forward
0 new messages