12.39
+------+ +------+ +------+
| |----->| |------>| |
|client| |proxy | |server|
| |<-----| |<------| |
+------+ +------+ +------+
as server as client
proxy play with client as a server, with server as a client, interesting.
the key point is when normal situation
+------+ +------+
| |----->| |
|client| |server|
| |<-----| |
+------+ +------+
HTTP request from client is something like
GET / HTTP/1.1
Host: address:port
but with proxy, it’ll be
GET http://address:port/ HTTP/1.1
Host: address:port
so proxy have to separate host from uri
A.
!INCLUDE "./code/12.39/proxy.c"
B.
move process into thread function
!INCLUDE "./code/12.39/proxy-thread.c"
how to benchmark:
run proxy
(cd chapter12/code/12.39; make && ./proxy)
# or
(cd chapter12/code/12.39; make && ./proxy-thread)
open another terminal, start a local http server
(python3 -m http.server 8000)
open one another terminal, benchmark
# -X means proxy, -n means how many requests, -c means concurrent
(ab -X localhost:5000 -n 100 -c 10 http://localhost:8000/)
当前内容版权归 DreamAndDead 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 DreamAndDead .