Performance tune for pubsub socket
This commit is contained in:
parent
2e354a3814
commit
29b2377a58
1 changed files with 10 additions and 7 deletions
|
@ -1,14 +1,17 @@
|
||||||
|
import os
|
||||||
import select
|
import select
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
import ujson
|
import ujson
|
||||||
from ipc_unix.utils import DEFAULT_SOCKET_READ_TIMEOUT, read_payload, socket_has_data
|
from ipc_unix.utils import read_payload, socket_has_data
|
||||||
|
|
||||||
|
|
||||||
class Subscriber:
|
class Subscriber:
|
||||||
def __init__(self, socket_path):
|
def __init__(self, socket_path):
|
||||||
self.socket_path = socket_path
|
self.socket_path = socket_path
|
||||||
self.socket = socket.socket(socket.AF_UNIX, type=socket.SOCK_STREAM)
|
self.socket = socket.socket(
|
||||||
|
socket.AF_UNIX, type=socket.SOCK_STREAM | socket.SOCK_NONBLOCK
|
||||||
|
)
|
||||||
self.socket.connect(self.socket_path)
|
self.socket.connect(self.socket_path)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -37,9 +40,11 @@ class Subscriber:
|
||||||
class Publisher:
|
class Publisher:
|
||||||
def __init__(self, socket_path):
|
def __init__(self, socket_path):
|
||||||
self.socket_path = socket_path
|
self.socket_path = socket_path
|
||||||
self.master_socket = socket.socket(socket.AF_UNIX, type=socket.SOCK_STREAM)
|
self.master_socket = socket.socket(
|
||||||
|
socket.AF_UNIX, type=socket.SOCK_STREAM | socket.SOCK_NONBLOCK
|
||||||
|
)
|
||||||
self.master_socket.bind(self.socket_path)
|
self.master_socket.bind(self.socket_path)
|
||||||
self.master_socket.listen(1)
|
self.master_socket.listen()
|
||||||
self.connections = []
|
self.connections = []
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
|
@ -57,9 +62,7 @@ class Publisher:
|
||||||
def write(self, message: dict):
|
def write(self, message: dict):
|
||||||
self.accept_new_connection()
|
self.accept_new_connection()
|
||||||
|
|
||||||
_, writable, errorable = select.select(
|
_, writable, errorable = select.select([], self.connections, [], 1)
|
||||||
[], self.connections, [], DEFAULT_SOCKET_READ_TIMEOUT
|
|
||||||
)
|
|
||||||
|
|
||||||
dead_sockets = []
|
dead_sockets = []
|
||||||
|
|
||||||
|
|
Reference in a new issue