Skip to content

Commit

Permalink
set TCP_NODELAY
Browse files Browse the repository at this point in the history
  • Loading branch information
rgerganov committed Apr 29, 2024
1 parent c3ed6ed commit eaf1543
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions examples/rpc/rpc-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -92,6 +93,14 @@ int main(int argc, char * argv[])
fprintf(stderr, "Failed to accept client connection\n");
return 1;
}
// set TCP_NODELAY to disable Nagle's algorithm
int flag = 1;
int ret = setsockopt(client_socket, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(int));
if (ret < 0) {
fprintf(stderr, "Failed to set TCP_NODELAY\n");
close(client_socket);
continue;
}
printf("Accepted client connection\n");
rpc_serve_client(backend, client_socket);
printf("Client connection closed\n");
Expand Down
7 changes: 7 additions & 0 deletions ggml-rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netdb.h>
#include <string.h>
#include <unistd.h>
Expand Down Expand Up @@ -57,6 +58,12 @@ static int socket_connect(const char * host, int port) {
if (sock < 0) {
return -1;
}
// set TCP_NODELAY to disable Nagle's algorithm
int flag = 1;
int ret = setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int));
if (ret < 0) {
return -1;
}
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
struct hostent * server = gethostbyname(host);
Expand Down

0 comments on commit eaf1543

Please sign in to comment.