Skip to content

Commit

Permalink
Support maxiov per connection type (redis#12234)
Browse files Browse the repository at this point in the history
Rather than a fixed iovcnt for connWritev, support maxiov per connection type instead.
A minor change to reduce memory for struct connection.

Signed-off-by: zhenwei pi <[email protected]>
  • Loading branch information
pizhenwei authored May 28, 2023
1 parent e775b34 commit cb78acb
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,15 @@ typedef struct ConnectionType {
struct connection {
ConnectionType *type;
ConnectionState state;
int last_errno;
int fd;
short int flags;
short int refs;
int last_errno;
unsigned short int iovcnt;
void *private_data;
ConnectionCallbackFunc conn_handler;
ConnectionCallbackFunc write_handler;
ConnectionCallbackFunc read_handler;
int fd;
};

#define CONFIG_BINDADDR_MAX 16
Expand Down
5 changes: 3 additions & 2 deletions src/networking.c
Original file line number Diff line number Diff line change
Expand Up @@ -1787,8 +1787,9 @@ client *lookupClientByID(uint64_t id) {
* and 'nwritten' is an output parameter, it means how many bytes server write
* to client. */
static int _writevToClient(client *c, ssize_t *nwritten) {
struct iovec iov[IOV_MAX];
int iovcnt = 0;
int iovmax = min(IOV_MAX, c->conn->iovcnt);
struct iovec iov[iovmax];
size_t iov_bytes_len = 0;
/* If the static reply buffer is not empty,
* add it to the iov array for writev() as well. */
Expand All @@ -1804,7 +1805,7 @@ static int _writevToClient(client *c, ssize_t *nwritten) {
listNode *next;
clientReplyBlock *o;
listRewind(c->reply, &iter);
while ((next = listNext(&iter)) && iovcnt < IOV_MAX && iov_bytes_len < NET_MAX_WRITES_PER_EVENT) {
while ((next = listNext(&iter)) && iovcnt < iovmax && iov_bytes_len < NET_MAX_WRITES_PER_EVENT) {
o = listNodeValue(next);
if (o->used == 0) { /* empty node, just release it and skip. */
c->reply_bytes -= o->size;
Expand Down
1 change: 1 addition & 0 deletions src/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ static connection *connCreateSocket(void) {
connection *conn = zcalloc(sizeof(connection));
conn->type = &CT_Socket;
conn->fd = -1;
conn->iovcnt = IOV_MAX;

return conn;
}
Expand Down
1 change: 1 addition & 0 deletions src/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ static connection *createTLSConnection(int client_side) {
tls_connection *conn = zcalloc(sizeof(tls_connection));
conn->c.type = &CT_TLS;
conn->c.fd = -1;
conn->c.iovcnt = IOV_MAX;
conn->ssl = SSL_new(ctx);
return (connection *) conn;
}
Expand Down
1 change: 1 addition & 0 deletions src/unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ static connection *connCreateUnix(void) {
connection *conn = zcalloc(sizeof(connection));
conn->type = &CT_Unix;
conn->fd = -1;
conn->iovcnt = IOV_MAX;

return conn;
}
Expand Down

0 comments on commit cb78acb

Please sign in to comment.