12.38
code in directory chapter12/code/12.38
files:
- sbuf.h, sbuf.c: prethreading package from section 12.5.4 in book. differences
are that add new functionssbuf_full
,sbuf_empty
. - tiny.h, tiny.c: origin tiny server from section 11.6 in book. differences are
we seperate function declarations into a .h file - main.c: listen new connections, create threads and adjust threads number dynamicly
see new functions in sbuf, sbuf_full
and sbuf_empty
/* Empty buf? */
int sbuf_empty(sbuf_t *sp) {
int e;
P(&sp->mutex); /* Lock the buffer */
e = sp->front == sp->rear;
V(&sp->mutex); /* Lock the buffer */
return e;
}
/* Full buf? */
int sbuf_full(sbuf_t *sp) {
int f;
P(&sp->mutex); /* Lock the buffer */
f = (sp->rear - sp->front) == sp->n;
V(&sp->mutex); /* Lock the buffer */
return f;
}
main.c
!INCLUDE "./code/12.38/main.c"
run server
(cd chapter12/code/12.38; make && ./main)
open another terminal and benchmark it
wrk -d4 http://localhost:5000
output
Running 4s test @ http://localhost:5000
2 threads and 10 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 130.44us 183.40us 9.03ms 98.06%
Req/Sec 11.08k 5.09k 17.78k 53.66%
90380 requests in 4.10s, 19.74MB read
Requests/sec: 22039.72
Transfer/sec: 4.81MB
当前内容版权归 DreamAndDead 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 DreamAndDead .