ijust implement simple tcp listener/server application in erlang and i test this code using 40000 tcp connections and it creates around 600 os thread in windows machine and i closed those 40K tcp connections but erlang VM doesnt release 600 os/windows threads. how do i optimise this, im looking forward for your reply
The windows implementation of erl_poll (which is the mechanism responsible for checking for new data on a socket) uses WaitForMultipleObjects. This API does not allow for more than 64 objects per call, so erl_poll creates threads that each listen to 64 Objects. These are the threads that you see.
There is no mechanism that removes these threads once that they are used, so they will remain until the system terminates. They are of course re-used if you in the future again use that many connections.
The code that does this is in: https://github.com/erlang/otp/blob/master/erts/emulator/sys/win32/erl_poll.c