Go to the documentation of this file.
28 #include <netinet/ip.h>
33 #include <sys/epoll.h>
35 #include <sys/socket.h>
80 if (errno == EAGAIN && spin == 1) {
111 err = poll(&pfd, 1, spin ? 0 : -1);
113 if (errno == EINTR) {
120 if (
err == 0 && spin)
continue;
125 }
while (err2 < 0 && errno == EINTR);
126 if (err2 < 0 && errno != EAGAIN) {
155 if (errno == EINTR)
continue;
159 if (
err == 0 && spin)
continue;
167 }
while (err2 < 0 && errno == EINTR);
168 if (errno == EAGAIN)
break;
179 return epoll_read_bytes(
args,
buf, 0);
183 return epoll_read_bytes(
args,
buf, 1);
194 size_t write_size =
args->msg_size;
199 if (errno == EINTR) {
238 epoll_fd = epoll_create(1);
244 args->epoll_fd = epoll_fd;
246 ev.events = EPOLLIN | EPOLLET;
247 ev.data.fd =
args->fds.read_fd;
291 return 1e9 *
static_cast<double>(tv.
tv_sec) +
static_cast<double>(tv.
tv_nsec);
301 const int kNumIters = 100000;
307 for (
i = 0;
i < kNumIters; ++
i) {
318 if (
i > kNumIters / 2) {
393 }
while (
err < 0 && errno == EINTR);
409 int fd = accept(listen_fd,
nullptr,
nullptr);
422 struct sockaddr_in
port;
423 struct sockaddr* sa_port =
reinterpret_cast<struct sockaddr*
>(&
port);
425 port.sin_family = AF_INET;
427 port.sin_addr.s_addr = INADDR_ANY;
430 if (listen_fd == -1) {
455 if (listen_fd != -1) {
469 if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0) {
484 if (pipe(cfds) < 0) {
489 if (pipe(sfds) < 0) {
502 "Strategy for doing reads, which is one of:\n"
503 " blocking: blocking read calls\n"
504 " same_thread_poll: poll() call on same thread \n"
506 " same_thread_epoll: epoll_wait() on same thread \n"
508 " spin_read: spinning non-blocking read() calls \n"
509 " spin_poll: spinning 0 timeout poll() calls \n"
511 " spin_epoll: spinning 0 timeout epoll_wait() calls \n"
516 "Type of socket used, one of:\n"
517 " tcp: fds are endpoints of a TCP connection\n"
518 " socketpair: fds come from socketpair()\n"
519 " pipe: fds come from pipe()\n";
522 fprintf(
stderr,
"%s usage:\n\n", argv0);
523 fprintf(
stderr,
"%s read_strategy socket_type msg_size\n\n", argv0);
524 fprintf(
stderr,
"where read_strategy is one of:\n");
525 fprintf(
stderr,
" blocking: blocking read calls\n");
526 fprintf(
stderr,
" same_thread_poll: poll() call on same thread \n");
528 fprintf(
stderr,
" same_thread_epoll: epoll_wait() on same thread \n");
530 fprintf(
stderr,
" spin_read: spinning non-blocking read() calls \n");
531 fprintf(
stderr,
" spin_poll: spinning 0 timeout poll() calls \n");
533 fprintf(
stderr,
" spin_epoll: spinning 0 timeout epoll_wait() calls \n");
535 fprintf(
stderr,
"and socket_type is one of:\n");
536 fprintf(
stderr,
" tcp: fds are endpoints of a TCP connection\n");
537 fprintf(
stderr,
" socketpair: fds come from socketpair()\n");
538 fprintf(
stderr,
" pipe: fds come from pipe()\n");
552 {
"same_thread_epoll", epoll_read_bytes_blocking, epoll_setup},
553 {
"spin_epoll", epoll_read_bytes_spin, epoll_setup},
562 if (strcmp(socket_type,
"tcp") == 0) {
564 }
else if (strcmp(socket_type,
"socketpair") == 0) {
566 }
else if (strcmp(socket_type,
"pipe") == 0) {
569 fprintf(
stderr,
"Invalid socket type %s\n", socket_type);
586 socket_type, client_args->
msg_size);
628 int main(
int argc,
char** argv) {
634 const char* read_strategy =
nullptr;
635 const char* socket_type =
nullptr;
655 if (read_strategy ==
nullptr) {
660 if (socket_type ==
nullptr) {
664 fprintf(
stderr,
"msg_size must be > 0\n");
675 if (strategy ==
nullptr) {
676 fprintf(
stderr,
"Invalid read strategy %s\n", read_strategy);
grpc_error_handle grpc_set_socket_reuse_addr(int fd, int reuse)
static int blocking_write_bytes(struct thread_args *args, char *buf)
static int poll_read_bytes_spin(struct thread_args *args, char *buf)
grpc_error_handle grpc_set_socket_low_latency(int fd, int low_latency)
return memset(p, 0, total)
static uv_os_fd_t server_fd
static int connect_client(struct sockaddr *addr, socklen_t len)
static const char * socket_types[]
static int set_socket_nonblocking(thread_args *args)
GPRAPI void gpr_free(void *ptr)
void gpr_cmdline_destroy(gpr_cmdline *cl)
int(* read_bytes)(struct thread_args *args, char *buf)
GPRAPI void * gpr_malloc(size_t size)
#define GRPC_LOG_IF_ERROR(what, error)
static int spin_read_bytes(thread_args *args, char *buf)
static int64_t start_time
static void server_thread(thread_args *args)
static int accept_server(int listen_fd)
static int run_benchmark(const char *socket_type, thread_args *client_args, thread_args *server_args)
static const char * socket_type_usage
static int blocking_read_bytes(thread_args *args, char *buf)
std::unique_ptr< Server > server
struct test_strategy test_strategy
grpc_error_handle grpc_set_socket_cloexec(int fd, int close_on_exec)
void grpc_histogram_destroy(grpc_histogram *h)
static uv_os_fd_t client_fd
const char * strategy_name
GPRAPI void gpr_log(const char *file, int line, gpr_log_severity severity, const char *format,...) GPR_PRINT_FORMAT_CHECK(4
void gpr_cmdline_add_string(gpr_cmdline *cl, const char *name, const char *help, const char **value)
static grpc_histogram * histogram
static int poll_read_bytes_blocking(struct thread_args *args, char *buf)
int create_socket(const char *socket_type, fd_pair *client_fds, fd_pair *server_fds)
static int read_bytes(int fd, char *buf, size_t read_size, int spin)
double grpc_histogram_percentile(grpc_histogram *h, double percentile)
int epoll_wait(uv__os390_epoll *lst, struct epoll_event *events, int maxevents, int timeout)
int main(int argc, char **argv)
struct thread_args thread_args
GPRAPI gpr_timespec gpr_now(gpr_clock_type clock)
static int do_nothing(thread_args *)
grpc_histogram * grpc_histogram_create(double resolution, double max_bucket_start)
static int poll_read_bytes(int fd, char *buf, size_t read_size, int spin)
static void server_thread_wrap(void *arg)
int(* setup)(struct thread_args *args)
#define GPR_ARRAY_SIZE(array)
int read(izstream &zs, T *x, Items items)
static int create_sockets_socketpair(fd_pair *client_fds, fd_pair *server_fds)
static void print_histogram(grpc_histogram *histogram)
void gpr_cmdline_add_int(gpr_cmdline *cl, const char *name, const char *help, int *value)
static int run_all_benchmarks(size_t msg_size)
void print_usage(char *argv0)
def listen(endpoint, test_case)
int epoll_ctl(uv__os390_epoll *lst, int op, int fd, struct epoll_event *event)
int(* setup)(struct thread_args *args)
static int create_sockets_pipe(fd_pair *client_fds, fd_pair *server_fds)
gpr_cmdline * gpr_cmdline_create(const char *description)
static int create_listening_socket(struct sockaddr *port, socklen_t len)
static void client_thread(thread_args *args)
static size_t bytes_written
int(* read_strategy)(struct thread_args *args, char *buf)
void grpc_histogram_add(grpc_histogram *h, double x)
grpc_error_handle grpc_set_socket_nonblocking(int fd, int non_blocking)
static test_strategy test_strategies[]
static const char * read_strategy_usage
int(* write_bytes)(struct thread_args *args, char *buf)
int gpr_cmdline_parse(gpr_cmdline *cl, int argc, char **argv)
static int create_sockets_tcp(fd_pair *client_fds, fd_pair *server_fds)
grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:17