Miguel Grinberg
4 years ago
No known key found for this signature in database
GPG Key ID: 36848B262DF5F06C
9 changed files with
143 additions and
3 deletions
-
socketio/base_manager.py
-
tests/performance/README.md
-
tests/performance/binary_packet.py
-
tests/performance/json_packet.py
-
tests/performance/namespace_packet.py
-
tests/performance/run.sh
-
tests/performance/server_receive.py
-
tests/performance/server_send.py
-
tests/performance/text_packet.py
|
|
@ -38,7 +38,7 @@ class BaseManager(object): |
|
|
|
|
|
|
|
def get_participants(self, namespace, room): |
|
|
|
"""Return an iterable with the active participants in a room.""" |
|
|
|
for sid, eio_sid in self.rooms[namespace][room].copy().items(): |
|
|
|
for sid, eio_sid in self.rooms[namespace][room]._fwdm.copy().items(): |
|
|
|
yield sid, eio_sid |
|
|
|
|
|
|
|
def connect(self, eio_sid, namespace): |
|
|
@ -59,8 +59,10 @@ class BaseManager(object): |
|
|
|
pass |
|
|
|
|
|
|
|
def sid_from_eio_sid(self, eio_sid, namespace): |
|
|
|
if namespace in self.rooms: |
|
|
|
return self.rooms[namespace][None].inverse.get(eio_sid) |
|
|
|
try: |
|
|
|
return self.rooms[namespace][None]._invm[eio_sid] |
|
|
|
except KeyError: |
|
|
|
pass |
|
|
|
|
|
|
|
def eio_sid_from_sid(self, sid, namespace): |
|
|
|
if namespace in self.rooms: |
|
|
|
|
|
@ -0,0 +1,5 @@ |
|
|
|
Performance |
|
|
|
=========== |
|
|
|
|
|
|
|
This directory contains several scripts and tools to test the performance of |
|
|
|
the project. |
|
|
@ -0,0 +1,22 @@ |
|
|
|
import time |
|
|
|
from socketio import packet |
|
|
|
|
|
|
|
|
|
|
|
def test(): |
|
|
|
p = packet.Packet(packet.EVENT, {'foo': b'bar'}) |
|
|
|
start = time.time() |
|
|
|
count = 0 |
|
|
|
while True: |
|
|
|
eps = p.encode() |
|
|
|
p = packet.Packet(encoded_packet=eps[0]) |
|
|
|
for ep in eps[1:]: |
|
|
|
p.add_attachment(ep) |
|
|
|
count += 1 |
|
|
|
if time.time() - start >= 5: |
|
|
|
break |
|
|
|
return count |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
count = test() |
|
|
|
print('binary_packet:', count, 'packets processed.') |
|
|
@ -0,0 +1,19 @@ |
|
|
|
import time |
|
|
|
from socketio import packet |
|
|
|
|
|
|
|
|
|
|
|
def test(): |
|
|
|
p = packet.Packet(packet.EVENT, {'foo': 'bar'}) |
|
|
|
start = time.time() |
|
|
|
count = 0 |
|
|
|
while True: |
|
|
|
p = packet.Packet(encoded_packet=p.encode()) |
|
|
|
count += 1 |
|
|
|
if time.time() - start >= 5: |
|
|
|
break |
|
|
|
return count |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
count = test() |
|
|
|
print('json_packet:', count, 'packets processed.') |
|
|
@ -0,0 +1,19 @@ |
|
|
|
import time |
|
|
|
from socketio import packet |
|
|
|
|
|
|
|
|
|
|
|
def test(): |
|
|
|
p = packet.Packet(packet.EVENT, 'hello', namespace='/foo') |
|
|
|
start = time.time() |
|
|
|
count = 0 |
|
|
|
while True: |
|
|
|
p = packet.Packet(encoded_packet=p.encode()) |
|
|
|
count += 1 |
|
|
|
if time.time() - start >= 5: |
|
|
|
break |
|
|
|
return count |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
count = test() |
|
|
|
print('namespace_packet:', count, 'packets processed.') |
|
|
@ -0,0 +1,7 @@ |
|
|
|
#!/bin/bash |
|
|
|
python text_packet.py |
|
|
|
python binary_packet.py |
|
|
|
python json_packet.py |
|
|
|
python namespace_packet.py |
|
|
|
python server_receive.py |
|
|
|
python server_send.py |
|
|
@ -0,0 +1,21 @@ |
|
|
|
import time |
|
|
|
import socketio |
|
|
|
|
|
|
|
|
|
|
|
def test(): |
|
|
|
s = socketio.Server(async_handlers=False) |
|
|
|
start = time.time() |
|
|
|
count = 0 |
|
|
|
s._handle_eio_connect('123', 'environ') |
|
|
|
s._handle_eio_message('123', '0') |
|
|
|
while True: |
|
|
|
s._handle_eio_message('123', '2["test","hello"]') |
|
|
|
count += 1 |
|
|
|
if time.time() - start >= 5: |
|
|
|
break |
|
|
|
return count |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
count = test() |
|
|
|
print('server_receive:', count, 'packets received.') |
|
|
@ -0,0 +1,26 @@ |
|
|
|
import time |
|
|
|
import socketio |
|
|
|
|
|
|
|
|
|
|
|
class Server(socketio.Server): |
|
|
|
def _send_packet(self, eio_sid, pkt): |
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
def test(): |
|
|
|
s = Server() |
|
|
|
start = time.time() |
|
|
|
count = 0 |
|
|
|
s._handle_eio_connect('123', 'environ') |
|
|
|
s._handle_eio_message('123', '0') |
|
|
|
while True: |
|
|
|
s.emit('test', 'hello') |
|
|
|
count += 1 |
|
|
|
if time.time() - start >= 5: |
|
|
|
break |
|
|
|
return count |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
count = test() |
|
|
|
print('server_send:', count, 'packets received.') |
|
|
@ -0,0 +1,19 @@ |
|
|
|
import time |
|
|
|
from socketio import packet |
|
|
|
|
|
|
|
|
|
|
|
def test(): |
|
|
|
p = packet.Packet(packet.EVENT, 'hello') |
|
|
|
start = time.time() |
|
|
|
count = 0 |
|
|
|
while True: |
|
|
|
p = packet.Packet(encoded_packet=p.encode()) |
|
|
|
count += 1 |
|
|
|
if time.time() - start >= 5: |
|
|
|
break |
|
|
|
return count |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
count = test() |
|
|
|
print('text_packet:', count, 'packets processed.') |