I acquire samples (integers) at a very high rate (several kilo samples per seconds) in a thread and put() them in a threading.Queue. The main thread get()s the samples one by one into a list of length 4096, then msgpacks them and finally sends them via ZeroMQ to a client. The client shows the chunks on the screen (print or plot). In short the original idea is, fill the queue with single samples, but empty it in large chunks.
Everything works 100% as expected. But the latter part i.e. accessing the queue is very very slow. Queue gets larger and the output always lags behind by several to tens of seconds.
My question is: how can I do something to make queue access faster? Is there a better approach?
collections.dequeis much faster thanthreading.Queueand also threadsafe but does not have all the features. Maybemultiprocessing.dummy(which actually uses threads) is worth a look, too for you.lists with 4096 samples in the sampling-thread and then put those lists as single items in the Queue - this would require less comparably slow calls to Queue-methods.queue, but comes at the cost of loss of samples of course.queueandmultiprocessingto see if it can get any better.