2

I wish to know which code is being executed in YAWS every time a new client uses its web server...

First I tried to understand how YAWS handles concurrent users... and trie the following .yaws page:

io:format("~nProcess Identifier: ~p  Port: ~p  Client: ~p  YAWS pid: ~p ~n",[self(), A#arg.clisock, A#arg.client_ip_port, A#arg.pid]).

which should return the Pid , port and ip of each client... I opened this page on the same browser (Firefox) and opened two distinct tabs... this was printed:

Process Identifier: <0.65.0>  Port: #Port<0.1211>  Client: {{127,0,0,1},60451}  YAWS pid: <0.65.0> 

Process Identifier: <0.65.0>  Port: #Port<0.1211>  Client: {{127,0,0,1},60451}  YAWS pid: <0.65.0> 

for some reason, the same port and pid are being returned (hence, YAWS isn't creating a new port or new pid for each client).

When I try this out on Chrome this was printed:

Process Identifier: <0.71.0>  Port: #Port<0.2998>  Client: {{127,0,0,1},60543}  YAWS pid: <0.71.0> 

Process Identifier: <0.71.0>  Port: #Port<0.2998>  Client: {{127,0,0,1},60543}  YAWS pid: <0.71.0> 

Hence, why is YAWS not opening a new port or pid for each tab on the same browser? Also, back to the original question, where and which code does YAWS spawns a new PID or opens a new port?

Thanks

1 Answer 1

6

Unless you're sure that your browsers open new HTTP connections for each tab, you're not really testing what you think you're testing. Instead, try this from a command line:

curl http://yaws_host:yaws_port/path/to/your/yaws/page.yaws
curl http://yaws_host:yaws_port/path/to/your/yaws/page.yaws    

Yes, run it twice, as that is guaranteed to use two separate connections. You will then see that Yaws uses two distinct Erlang processes and TCP connections to handle the two requests:

Process Identifier: <0.59.0>  Port: #Port<0.1181>  Client: {{127,0,0,1},64977}  YAWS pid: <0.59.0>
Process Identifier: <0.64.0>  Port: #Port<0.3268>  Client: {{127,0,0,1},64978}  YAWS pid: <0.64.0>

As for where the Yaws code for dealing with connections resides, you can look in yaws_server.erl, in particular at the acceptor/1 function which launches processes to accept connections and the do_listen/2 function which opens sockets for listening.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.