User Tools

Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
c:thrsrv-bs [2019-06-01 15:56]
ziggi created
c:thrsrv-bs [2019-06-04 12:14] (current)
Line 76: Line 76:
 } }
  
-int queue_back(queue_t* q, int x) {+int queue_push(queue_t* q, int x) {
     if (q == NULL) return -1;     if (q == NULL) return -1;
     pthread_mutex_lock(&​q->​mutex);​     pthread_mutex_lock(&​q->​mutex);​
     int res = -1;     int res = -1;
-    if (> q->​capacity) {+    if ((q->​size ​1) > q->​capacity) {
         int newcapacity = q->​capacity * 2;         int newcapacity = q->​capacity * 2;
         void* items = realloc(q->​items,​ sizeof(int) * newcapacity);​         void* items = realloc(q->​items,​ sizeof(int) * newcapacity);​
Line 88: Line 88:
         }         }
     }     }
-    if (x < q->​capacity) {; +    if ((q->size + 1) q->​capacity) { 
-        q->rear = (q->rear + 1) q->​capacity; +        ​pthread_mutex_unlock(&​(q->mutex))
-        q->items[q->​rear] = x+        ​return ​-1;
-        ​q->​size++;​ +
-        res = 1;+
     }     }
 +    q->rear = (q->rear + 1) % q->​capacity;​
 +    q->​items[q->​rear] = x;
 +    q->​size++;​
 +    res = 1;
     pthread_mutex_unlock(&​(q->​mutex));​     pthread_mutex_unlock(&​(q->​mutex));​
     return res;     return res;
Line 157: Line 159:
  
 int wrkpool_enqueue(wrkpool_t* wp, int newsock) { int wrkpool_enqueue(wrkpool_t* wp, int newsock) {
-    ​queue_back(wp->​queue,​ newsock);+    ​queue_push(wp->​queue,​ newsock);
     for (int i = 0; i < wp->​size;​ i++) {     for (int i = 0; i < wp->​size;​ i++) {
         worker_t* w = wp->​workers[i];​         worker_t* w = wp->​workers[i];​
Line 307: Line 309:
 } }
 </​code>​ </​code>​
 +===benchmark===
 +
 +<​file>​
 +$ ab -s 20 -c 1000 -n100000 '​http://​127.0.0.1:​1024/'​
 +This is ApacheBench,​ Version 2.3 <​$Revision:​ 1826891 $>
 +Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://​www.zeustech.net/​
 +Licensed to The Apache Software Foundation, http://​www.apache.org/​
 +
 +Benchmarking 127.0.0.1 (be patient)
 +Completed 10000 requests
 +Completed 20000 requests
 +Completed 30000 requests
 +Completed 40000 requests
 +Completed 50000 requests
 +Completed 60000 requests
 +Completed 70000 requests
 +Completed 80000 requests
 +Completed 90000 requests
 +Completed 100000 requests
 +Finished 100000 requests
 +
 +
 +Server Software: ​       Srv11/0.1
 +Server Hostname: ​       127.0.0.1
 +Server Port:            1024
 +
 +Document Path:          /
 +Document Length: ​       142 bytes
 +
 +Concurrency Level: ​     1000
 +Time taken for tests: ​  3.819 seconds
 +Complete requests: ​     100000
 +Failed requests: ​       0
 +Total transferred: ​     30300000 bytes
 +HTML transferred: ​      ​14200000 bytes
 +Requests per second: ​   26183.30 [#/sec] (mean)
 +Time per request: ​      ​38.192 [ms] (mean)
 +Time per request: ​      0.038 [ms] (mean, across all concurrent requests)
 +Transfer rate:          7747.60 [Kbytes/​sec] received
 +
 +Connection Times (ms)
 +              min  mean[+/-sd] median ​  max
 +Connect: ​       0   ​12 ​  ​7.4 ​    ​10 ​     55
 +Processing: ​    ​5 ​  ​20 ​ 41.3     ​11 ​    616
 +Waiting: ​       0   ​15 ​ 39.9      8     487
 +Total: ​        ​13 ​  ​32 ​ 42.9     ​21 ​    632
 +
 +Percentage of the requests served within a certain time (ms)
 +  50%     21
 +  66%     22
 +  75%     23
 +  80%     23
 +  90%     59
 +  95%     80
 +  98%    205
 +  99%    269
 + ​100% ​   632 (longest request)
 +</​file>​
 +
 +===Nginx on the same system===
 +
 +<​file>​
 +$ ab -s 20 -c 1000 -n100000 '​http://​127.0.0.1:​80/'​
 +This is ApacheBench,​ Version 2.3 <​$Revision:​ 1826891 $>
 +Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://​www.zeustech.net/​
 +Licensed to The Apache Software Foundation, http://​www.apache.org/​
 +
 +Benchmarking 127.0.0.1 (be patient)
 +Completed 10000 requests
 +Completed 20000 requests
 +Completed 30000 requests
 +Completed 40000 requests
 +Completed 50000 requests
 +Completed 60000 requests
 +Completed 70000 requests
 +Completed 80000 requests
 +Completed 90000 requests
 +Completed 100000 requests
 +Finished 100000 requests
 +
 +
 +Server Software: ​       nginx/​1.14.2
 +Server Hostname: ​       127.0.0.1
 +Server Port:            80
 +
 +Document Path:          /
 +Document Length: ​       185 bytes
 +
 +Concurrency Level: ​     1000
 +Time taken for tests: ​  3.841 seconds
 +Complete requests: ​     100000
 +Failed requests: ​       0
 +Non-2xx responses: ​     100000
 +Total transferred: ​     37700000 bytes
 +HTML transferred: ​      ​18500000 bytes
 +Requests per second: ​   26035.91 [#/sec] (mean)
 +Time per request: ​      ​38.408 [ms] (mean)
 +Time per request: ​      0.038 [ms] (mean, across all concurrent requests)
 +Transfer rate:          9585.49 [Kbytes/​sec] received
 +
 +Connection Times (ms)
 +              min  mean[+/-sd] median ​  max
 +Connect: ​       0   10 111.9      5    3011
 +Processing: ​    ​5 ​  ​18 ​ 27.0     ​12 ​    542
 +Waiting: ​       0   ​16 ​ 25.1     ​11 ​    534
 +Total: ​         9   28 115.0     ​17 ​   3019
 +
 +Percentage of the requests served within a certain time (ms)
 +  50%     17
 +  66%     19
 +  75%     20
 +  80%     21
 +  90%     37
 +  95%     65
 +  98%     78
 +  99%    241
 + ​100% ​  3019 (longest request)
 +</​file>​
  
 ---- ----
 [<>] [<>]