rework tcp server

motivation: a thread creating a lot of messages like a polling loop
with very short polling frequency or a fast polling connection might
monopolize the output of message over receiving new messages.
In addition, the current design has a latency of 0.3 sec for the
output of asynchronous replies.

Anyway, the output queue is just extending the network output buffer,
which is usally big enough.

- change the name of 'queue_async_reply' to 'send_reply'.
  This method anyway was not only used for async replies.

- send_reply is directly sending the reply instead of putting into the
  queue. It will slow down the calling thread, if the output buffer
  is full, which is desired behaviour.

Change-Id: I305669be2f7c027355b43421432f32be9c166ed4
Reviewed-on: https://forge.frm2.tum.de/review/c/sine2020/secop/playground/+/23119
Tested-by: JenkinsCodeReview <bjoern_pedersen@frm2.tum.de>
Reviewed-by: Enrico Faulhaber <enrico.faulhaber@frm2.tum.de>
Reviewed-by: Markus Zolliker <markus.zolliker@psi.ch>
This commit is contained in:
2020-05-20 15:20:19 +02:00
parent 31ae0a88b4
commit f7a6ba8b5b
3 changed files with 35 additions and 54 deletions

View File

@ -25,8 +25,8 @@
Interface to the service offering part:
- 'handle_request(connectionobj, data)' handles incoming request
it returns the (sync) reply, and it may call 'queue_async_reply(data)'
on the connectionobj
it returns the (sync) reply, and it may call 'send_reply(data)'
on the connectionobj or on activated connections
- 'add_connection(connectionobj)' registers new connection
- 'remove_connection(connectionobj)' removes now longer functional connection
@ -98,7 +98,7 @@ class Dispatcher:
# all generic subscribers
listeners.update(self._active_connections)
for conn in listeners:
conn.queue_async_reply(msg)
conn.send_reply(msg)
def announce_update(self, modulename, pname, pobj):
"""called by modules param setters to notify subscribers of new values
@ -275,7 +275,8 @@ class Dispatcher:
def handle_request(self, conn, msg):
"""handles incoming request
will call 'queue_async_reply(data)' on conn or return reply
will return return reply, may send replies to conn or
activated connections in addition
"""
self.log.debug('Dispatcher: handling msg: %s' % repr(msg))
@ -360,11 +361,11 @@ class Dispatcher:
for modulename, pname in modules:
moduleobj = self._modules.get(modulename, None)
if pname:
conn.queue_async_reply(make_update(modulename, moduleobj.parameters[pname]))
conn.send_reply(make_update(modulename, moduleobj.parameters[pname]))
continue
for pobj in moduleobj.accessibles.values():
if isinstance(pobj, Parameter) and pobj.export:
conn.queue_async_reply(make_update(modulename, pobj))
conn.send_reply(make_update(modulename, pobj))
return (ENABLEEVENTSREPLY, specifier, None) if specifier else (ENABLEEVENTSREPLY, None, None)
def handle_deactivate(self, conn, specifier, data):