From d7ee5d2282d39b3d816149a1797b52d671c99478 Mon Sep 17 00:00:00 2001 From: FUJITA Tomonori Date: Sat, 25 Feb 2012 11:47:15 +0900 Subject: [PATCH] yield the CPU to other greenlets We need to yield the CPU to other greenlets. Otherwise, ryu can't accept new switches or handle the existing switches. The limit is arbitrary. I guess that we need to think about the better approach in the future (e.g. non greenlet framework). Signed-off-by: FUJITA Tomonori --- ryu/controller/controller.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ryu/controller/controller.py b/ryu/controller/controller.py index 3c6c6dea..886ee311 100644 --- a/ryu/controller/controller.py +++ b/ryu/controller/controller.py @@ -114,6 +114,7 @@ class Datapath(object): buf = bytearray() required_len = ofproto.OFP_HEADER_SIZE + count = 0 while self.is_active: ret = self.socket.recv(required_len) if len(ret) == 0: @@ -134,6 +135,15 @@ class Datapath(object): buf = buf[required_len:] required_len = ofproto.OFP_HEADER_SIZE + # We need to schedule other greenlets. Otherwise, ryu + # can't accept new switches or handle the existing + # switches. The limit is arbitrary. We need the better + # approach in the future. + count += 1 + if count > 2048: + count = 0 + gevent.sleep(0) + @_deactivate def _send_loop(self): while self.is_active: