python - Log messages via TCP, significantly slower than similar code in Java -


in python 3 have queuehandler attached logger , queuelistener shipping logrecords sockethandler sends logs via tcp java app that's listening.

both programs run on localhost.

import logging import queue  log_q = queue.queue(-1) logger = logging.getlogger('testlogger') socket_handler = logging.handlers.sockethandler('localhost', 1337) q_handler = logging.handlers.queuehandler(log_q) q_listener = logging.handlers.queuelistener(log_q, socket_handler) logger.addhandler(q_handler) q_listener.start() 

i'm sending logrecords large lists attached them.

logger.info("prox_marker", extra={'vector': [some_list]}) 

where [some_list] list of ~100k double values.

i run following code test throughput:

for in range(1000):     logger.info("prox_marker", extra={'vector': [some_list]}) 

which takes 30-35 seconds complete.

if run similar test in java, java app twice fast.

in python queuehandler/-listener + sockethandler setup manages send 3 messages every 10 put in queue. time program finishes it'll have sent ~300 msgs 700 still in queue sent after main program finished.

the queuehandler/-listener use default, change default sockethandler use custom serializing method.

my goal (in case wasn't obvious) try , speed python code. unfortunately i'm still not 100% sure what's causing slow behavior in first place. might have socket (which know little about, i've tried playing around various timeout setting , tcp_nodelay - no avail).

i've tried ditch queuehandler/-listener , use sockethandler directly takes same amount of time before i'm assuming threading isn't issue.

any tips on issue might or how make faster appreciated.


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -