On Thu, Mar 26, 2015 at 11:41 AM, Llorente Santos Jesus <[email protected]> wrote: > I couldn’t find an elegant way within Ryu to open a socket and listen to it > within my application. At the moment, I am spawning a new thread from my own > app and using select over the socket file descriptor. Is there any other > (better) way of doing this?
I use the built in wrapped eventlet hub methods in my ovsdb implementation: https://github.com/jkoelker/ryu/blob/ovsdb/ryu/services/protocols/ovsdb/manager.py#L71 If you are not worried about constraining yourself to the wrapped hub implementation, then you could use `eventlet.serve()` to achieve the same result. > I was thinking something like a class that > could be extended, then implement the “selectable” methods (fileno) and that > would be registered in Ryu as a new type of event that would trigger the > callback afterwards. This would be cool. Although I would leave the actual select implementation to eventlet and just use the pattern of spawning a new greenthread to handle each client socket. Every read or write to the socket will allow eventlet an opportunity to context switch. A good example of this pattern is https://github.com/eventlet/eventlet/blob/master/examples/chat_server.py > This could reduce the number of threads required if we were to run several > Ryu apps and them all would require external communications, like some > external triggers or even a management interface. Greenthreads are cheap to create, and pretty scaleable within a single process/thread so I don't think the goal should be to reduce them. To scale out multicore, the pattern most used is similar to the apache prefork model. Start the sockets in a master process, fork N childs, then pass the socket into each child process which then runs identical copies of the apps all using greenthreads to provide concurrency on the socket. I don't think there is any plumbing in Ryu currently for this method, but shouldn't be too bad to add in in a custom manager app that the main Ryu process would start. Happy Hacking! 7-11 ------------------------------------------------------------------------------ Dive into the World of Parallel Programming The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ _______________________________________________ Ryu-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ryu-devel
