Changes in benchmark/io/http/http_ring.cpp [a80db97:eeb4866]
- File:
-
- 1 edited
-
benchmark/io/http/http_ring.cpp (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
benchmark/io/http/http_ring.cpp
ra80db97 reeb4866 20 20 socklen_t *addrlen; 21 21 int flags; 22 unsigned cnt;23 22 } acpt; 24 23 … … 68 67 thread_local stats_block_t stats; 69 68 stats_block_t global_stats; 70 71 thread_local struct __attribute__((aligned(128))) {72 size_t to_submit = 0;73 } local;74 69 75 70 // Get an array of current connections … … 197 192 static void submit(struct io_uring * ring, struct io_uring_sqe * sqe, connection * conn) { 198 193 (void)ring; 199 local.to_submit++;200 194 #ifdef USE_ASYNC 201 195 io_uring_sqe_set_flags(sqe, IOSQE_ASYNC); … … 412 406 switch(state) { 413 407 case ACCEPTING: 414 //connection::accept(ring, opt);408 connection::accept(ring, opt); 415 409 newconn(ring, res); 416 410 break; … … 426 420 427 421 //========================================================= 428 extern "C" {429 #include <sys/eventfd.h> // use for termination430 }431 432 422 // Main loop of the WebServer 433 423 // Effectively uses one thread_local copy of everything per kernel thread … … 437 427 struct io_uring * ring = opt.ring; 438 428 439 int blockfd = eventfd(0, 0);440 if (blockfd < 0) {441 fprintf( stderr, "eventfd create error: (%d) %s\n", (int)errno, strerror(errno) );442 exit(EXIT_FAILURE);443 }444 445 int ret = io_uring_register_eventfd(ring, blockfd);446 if (ret < 0) {447 fprintf( stderr, "io_uring S&W error: (%d) %s\n", (int)-ret, strerror(-ret) );448 exit(EXIT_FAILURE);449 }450 451 429 // Track the shutdown using a event_fd 452 430 char endfd_buf[8]; … … 455 433 // Accept our first connection 456 434 // May not take effect until io_uring_submit_and_wait 457 for(unsigned i = 0; i < opt.acpt.cnt; i++) { 458 connection::accept(ring, opt); 459 } 435 connection::accept(ring, opt); 460 436 461 437 int reset = 1; // Counter to print stats once in a while … … 465 441 while(!done) { 466 442 // Submit all the answers we have and wait for responses 467 int ret = io_uring_submit(ring); 468 local.to_submit = 0; 443 int ret = io_uring_submit_and_wait(ring, 1); 469 444 470 445 // check errors … … 477 452 sqes += ret; 478 453 call++; 479 480 481 eventfd_t val;482 ret = eventfd_read(blockfd, &val);483 484 // check errors485 if (ret < 0) {486 fprintf( stderr, "eventfd read error: (%d) %s\n", (int)errno, strerror(errno) );487 exit(EXIT_FAILURE);488 }489 454 490 455 struct io_uring_cqe *cqe; … … 498 463 break; 499 464 } 500 501 if(local.to_submit > 30) break;502 465 503 466 auto req = (class connection *)cqe->user_data; … … 546 509 #include <pthread.h> // for pthreads 547 510 #include <signal.h> // for signal(SIGPIPE, SIG_IGN); 511 #include <sys/eventfd.h> // use for termination 548 512 #include <sys/socket.h> // for sockets in general 549 513 #include <netinet/in.h> // for sockaddr_in, AF_INET … … 564 528 unsigned entries = 256; // number of entries per ring/kernel thread 565 529 unsigned backlog = 262144; // backlog argument to listen 566 unsigned preaccept = 1; // start by accepting X per threads567 530 bool attach = false; // Whether or not to attach all the rings 568 531 bool sqpoll = false; // Whether or not to use SQ Polling … … 571 534 // Arguments Parsing 572 535 int c; 573 while ((c = getopt (argc, argv, "t:p:e:b: c:aS")) != -1) {536 while ((c = getopt (argc, argv, "t:p:e:b:aS")) != -1) { 574 537 switch (c) 575 538 { … … 585 548 case 'b': 586 549 backlog = atoi(optarg); 587 break;588 case 'c':589 preaccept = atoi(optarg);590 550 break; 591 551 case 'a': … … 721 681 thrd_opts[i].acpt.addrlen = (socklen_t*)&addrlen; 722 682 thrd_opts[i].acpt.flags = 0; 723 thrd_opts[i].acpt.cnt = preaccept;724 683 thrd_opts[i].endfd = efd; 725 684 thrd_opts[i].ring = &thrd_rings[i].storage;
Note:
See TracChangeset
for help on using the changeset viewer.