Performance tune for pubsub socket

This commit is contained in:
Jake Howard 2018-12-08 13:07:26 +00:00
parent 2e354a3814
commit 29b2377a58
Signed by: jake
GPG key ID: 57AFB45680EDD477

View file

@ -1,14 +1,17 @@
import os
import select
import socket
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:
def __init__(self, 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)
@property
@ -37,9 +40,11 @@ class Subscriber:
class Publisher:
def __init__(self, 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.listen(1)
self.master_socket.listen()
self.connections = []
def close(self):
@ -57,9 +62,7 @@ class Publisher:
def write(self, message: dict):
self.accept_new_connection()
_, writable, errorable = select.select(
[], self.connections, [], DEFAULT_SOCKET_READ_TIMEOUT
)
_, writable, errorable = select.select([], self.connections, [], 1)
dead_sockets = []