EZLippi / WebBench

Webbench是Radim Kolar在1997年写的一个在linux下使用的非常简单的网站压测工具。它使用fork()模拟多个客户端同时访问我们设定的URL,测试网站在压力下工作的性能,最多可以模拟3万个并发连接去测试网站的负载能力。官网地址:http://home.tiscali.cz/~cz210552/webbench.html
GNU General Public License v3.0
2.66k stars 1.15k forks source link

Ask about the purpose and meaning of some code #18

Open ucsk opened 4 years ago

ucsk commented 4 years ago

This was the first project I studied, probably because of my limited ability, and I found that some places were not well understood. The following three points are some of my questions. Thank you for your guidance.

(1) Why isn't pid < 3 here? Is there any special meaning for pid being 2? https://github.com/EZLippi/WebBench/blob/b1acf3c01cc914729fe188dfc8ed761858028d4f/webbench.c#L411-L416

(2) Why does the bench() function return i? Isn't this the speed value that the parent process successfully read the last time? Could I change the program to return 0? https://github.com/EZLippi/WebBench/blob/b1acf3c01cc914729fe188dfc8ed761858028d4f/webbench.c#L435 (3) Add close(sock); is it more rigorous? https://github.com/EZLippi/WebBench/blob/b1acf3c01cc914729fe188dfc8ed761858028d4f/socket.c#L54-L55

hewei-nju commented 3 years ago

This was the first project I studied, probably because of my limited ability, and I found that some places were not well understood. The following three points are some of my questions. Thank you for your guidance.

(1) Why isn't pid < 3 here? Is there any special meaning for pid being 2? https://github.com/EZLippi/WebBench/blob/b1acf3c01cc914729fe188dfc8ed761858028d4f/webbench.c#L411-L416

(2) Why does the bench() function return i? Isn't this the speed value that the parent process successfully read the last time? Could I change the program to return 0? https://github.com/EZLippi/WebBench/blob/b1acf3c01cc914729fe188dfc8ed761858028d4f/webbench.c#L435

(3) Add close(sock); is it more rigorous? https://github.com/EZLippi/WebBench/blob/b1acf3c01cc914729fe188dfc8ed761858028d4f/socket.c#L54-L55

My personal opinion: (1): Because in common Linux operating systems, the PID of 0 and 1 have been occupied by the process operating system and the software which cooperates with the operating system.

(2): Currently, I'm facing the same problem with you, and I think you are true.

(3): Use man 3 connect, and I have found this sentenceAPPLICATION USAGE: If connect() fails, the state of the socket is unspecified. Conforming applications should close the file descriptor and create a new socket before attempting to reconnect. So I agree with you.