Hi Tom,

I used the attached script (Ryu App) to test "eventlet.green.zmg".
Please note that you need to install ZeroMQ before running it.
e.g.)
  $ pip install pyzmq

Could you try this app first?
e.g.)
  $ ryu-manager test_zeromq.py

Thanks,
Iwase


On 2017年06月08日 21:42, Tom De Schepper wrote:
> Hi Iwase,
> 
> Thanks for you fast reply.
> 
> We didn't tried out "eventlet.green.zmq" upfront, but for now we are not able 
> to get it working. 
> Do you have a basic example that successfully uses the  "eventlet.green.zmg'?
> 
> Besides the "eventlet.green.zmq" suggestion, do you happen to have any other 
> good direction that we might be able to apply?
> 
> Best regards,
> Tom
> 
> 2017-06-07 3:43 GMT+02:00 Iwase Yusuke <iwase.yusu...@gmail.com 
> <mailto:iwase.yusu...@gmail.com>>:
> 
>     Hi Tom,
> 
> 
>     On 2017年06月06日 20:54, Tom De Schepper wrote:
>     > Hi all,
>     >
>     > Some colleagues and I are interested in using the Ryu controller 
> together with a program of our own to control and monitor network components. 
> To this extend, it is necessary to set up some form of communication between 
> the programs. For that, we want to use the ZeroMQ framework 
> (http://zguide.zeromq.org/page:all <http://zguide.zeromq.org/page:all>) that 
> allows you to set up sockets between different components and handles the 
> sending and receiving of messages. The idea is to make our own app at the Ryu 
> side that listens and transmits messages to ZMQ and handles interaction with 
> virtual switches in the network. However, we ran into issues when 
> implementing the communication part in our Ryu app.
>     >
>     > We managed to made the app transmit messages by spawning a new hub with 
> a function that contains a while loop and every second will transmit 
> something. This works fine. However, the other way around won’t work.  Upon 
> initialization of the ZeroMQ communication elements (in the constructor of 
> our app) all functionality blocks. In other words,  opening the communication 
> socket causes blocking of all other hubs/processes within Ryu. We have tried, 
> without success, solving this in different manners, by using different 
> communication models (e.g., pub-sub), threads, the Ryu hub class, the 
> multiprocessing framework of Python, etc. .
>     >
>     > We have no idea what causes this blocking behavior and were wondering 
> if somebody within the community would have an idea. We checked out the 
> implementation of the Ryu hub class and noticed that it uses underneath 
> eventlets/greenlets, but are not sure if the interaction with that might 
> cause the problem.
> 
>     As you said, this problem seems to be caused by the compatibility between 
> ZeroMQ and eventlet.
>     GreenThread of eventlet is unexpectedly blocked if the native thread on 
> which GreenThread working.
> 
>     Fist, have you tried "eventlet.green.zmq"?
>     This module provides "greenthread aware version of pyzmq".
>       http://eventlet.net/doc/modules/zmq.html 
> <http://eventlet.net/doc/modules/zmq.html>
> 
>     If it does not work well, you need to spawn the native thread for ZeroMQ 
> socket, I guess,
>     but it might be difficult...
> 
>     Thanks,
>     Iwase
> 
> 
>     >
>     > We would appreciate any comments or feedback.
>     >
>     > Thanks in advance and best regards!
>     > Tom
>     >
>     >
>     >
>     > 
> ------------------------------------------------------------------------------
>     > Check out the vibrant tech community on one of the world's most
>     > engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>     >
>     >
>     >
>     > _______________________________________________
>     > Ryu-devel mailing list
>     > Ryu-devel@lists.sourceforge.net <mailto:Ryu-devel@lists.sourceforge.net>
>     > https://lists.sourceforge.net/lists/listinfo/ryu-devel 
> <https://lists.sourceforge.net/lists/listinfo/ryu-devel>
>     >
> 
> 
from eventlet.green import zmq

from ryu.base import app_manager
from ryu.lib import hub


class MyRyuApp(app_manager.RyuApp):

    def _server_loop(self):
        context = zmq.Context()
        socket = context.socket(zmq.REP)
        socket.bind("tcp://*:5555")

        while True:
            message = socket.recv()
            message = message.decode('utf-8')
            self.logger.info("[Server] Received request: %s", message)

            hub.sleep(5)

            message = 'World %s' % message[-1]
            self.logger.info("[Server] Sending response: %s", message)
            socket.send(message.encode('utf-8'))

    def _client_loop(self):
        hub.sleep(5)
        context = zmq.Context()
        socket = context.socket(zmq.REQ)
        socket.connect("tcp://localhost:5555")

        for i in range(5):
            message = 'Hello %d' % i
            self.logger.info("[Client] Sending request: %s", message)
            socket.send(message.encode('utf-8'))

            hub.sleep(3)

            message = socket.recv()
            message = message.decode('utf-8')
            self.logger.info("[Client] Received response: %s", message)

    def start(self):
        self.threads.append(hub.spawn(self._server_loop))
        self.threads.append(hub.spawn(self._client_loop))
        return hub.spawn(self._event_loop)
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Ryu-devel mailing list
Ryu-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to