开发者

Perl way to create sockets quickly (1000+)

开发者 https://www.devze.com 2023-01-06 23:45 出处:网络
I have a Perl server and when it boots up, it connects to 1000+ clients. It takes开发者_StackOverflow中文版 about 30-45 minutes to setup all the connections with SSL. I\'m trying to decrease the start

I have a Perl server and when it boots up, it connects to 1000+ clients. It takes开发者_StackOverflow中文版 about 30-45 minutes to setup all the connections with SSL. I'm trying to decrease the start time to something more reasonable. I tried playing with threads to offload the work, but can't get it to work. Creating the socket in one thread and getting it back to the caller doesn't quite work as expected. Tried passing the file descriptor and recreating with IO::Socket::SSL->new_from_fd() to recreate the socket back in the caller but fails.

Does anyone have any suggestions as to how to approach creating this many sockets quickly? Or at least faster than O(n)...

UPDATE: Looks like POE framework is definitely something that I want to explore. The docs sound like it can do what I need. I'm building a Proof of concept now and having trouble specifically with accessing the created Socket objects in the Sessions. I can create the sockets in the POE sessions, but then after they are done, I want my main program to collect the created sockets into one hash. Anyone know how to retrieve objects from POE Sessions?

UPDATE: Have an idea involving either using a global variable and adding the sockets to that within the sessions, or keeping references to the created sessions and accessing their heaps to aggregate them. Trying it now...


Have a look at this TCP SSL Client code in POE. The example can be easily extended to do what you requested. If you haven't coded in POE before, there's a learning curve, but it's very well documented.

0

精彩评论

暂无评论...
验证码 换一张
取 消