diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2012-02-25 11:47:15 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2012-03-01 09:11:29 +0900 |
commit | d7ee5d2282d39b3d816149a1797b52d671c99478 (patch) | |
tree | d254ad45ac89e632e26d37375c832860898d86ce | |
parent | f6741e9c9345ae282679b40fc11da5188c028eee (diff) |
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 <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/controller/controller.py | 10 |
1 files changed, 10 insertions, 0 deletions
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: |