queue

why doesn't a simple python producer/consumer multi-threading program speed up by adding the number of workers?

若如初见. 提交于 2019-12-10 19:19:10
问题 The code below is almost identical to the python official Queue example at http://docs.python.org/2/library/queue.html from Queue import Queue from threading import Thread from time import time import sys num_worker_threads = int(sys.argv[1]) source = xrange(10000) def do_work(item): for i in xrange(100000): pass def worker(): while True: item = q.get() do_work(item) q.task_done() q = Queue() for item in source: q.put(item) start = time() for i in range(num_worker_threads): t = Thread(target

Python asyncio task ordering

走远了吗. 提交于 2019-12-10 19:08:50
问题 I have a question about how the event loop in python's asyncio module manages outstanding tasks. Consider the following code: import asyncio @asyncio.coroutine def a(): for i in range(0, 3): print('a.' + str(i)) yield @asyncio.coroutine def b(): for i in range(0, 3): print('b.' + str(i)) yield @asyncio.coroutine def c(): for i in range(0, 3): print('c.' + str(i)) yield tasks = [ asyncio.Task(a()), asyncio.Task(b()), asyncio.Task(c()), ] loop = asyncio.get_event_loop() loop.run_until_complete

MSMQ slow queue reading

我们两清 提交于 2019-12-10 18:46:04
问题 I am using an open source .Net library which uses MSMQ underneath. After about a week or 2, the service slows down (not timed exactly but general guess). It appears that what is happening is messages from MSMQ are only being read exactly once every 10 seconds. Normally, they are read instantly. So they will be read at T+10sec, T+20sec, T+30sec, etc. independent of when the message was sent (i.e. sometimes it takes 3 seconds for the message to be read, other times 9 seconds). The current way I

Does performSelectorInBackground spawn new thread for each call?

只谈情不闲聊 提交于 2019-12-10 18:38:18
问题 Does performSelectorInBackground spawn a new thread for each call or does it share a thread (which is not main thread) for all calls (maybe queued)? 回答1: A new thread is created with each call to -performSelectorInBackground:withObject: From the Threading Programming Guide Using NSObject to Spawn a Thread In iOS and Mac OS X v10.5 and later, all objects have the ability to spawn a new thread and use it to execute one of their methods. The performSelectorInBackground:withObject: method creates

Recycle Freed Objects

孤人 提交于 2019-12-10 18:09:55
问题 suppose I need to allocate and delete object on heap frequently (of arbitrary size), is there any performance benefit if instead of deleting those objects, I will return it back to some "pool" to be reused later? would it give benefit by reduce heap allocation/deallocation?, or it will be slower compared to memory allocator performance, since the "pool" need to manage a dynamic collection of pointers. my use case: suppose I create a queue container based on linked list, and each node of that

async.queue with async/await style functions

纵饮孤独 提交于 2019-12-10 17:50:09
问题 I'm trying to create a function that builds a queue from an array of objects and then processes each object by calling a number of functions. The processing functions are asynchronous functions which, prior to needing to queue, I'd implemented using the async/await pattern. I think this is necessary as each relies on the output of the previous and I don't want to have a tonne of nested promise.then's i.e. previously I had: await Promise.all(messages.map(async(message) => { let activity =

working example of multiprocessing.Queue

一笑奈何 提交于 2019-12-10 17:29:08
问题 I am looking for a working example of multiprocessing.Queue after being pointed to it from this question: Python utilizing multiple processors I came across this, but it only seems to use one of my 12 processors even when I change num_processes=12 . I also changed num_jobs = 200000 so that it wouldn't complete so fast. Can someone tell me what's wrong with that example or point me to one that works? 回答1: There are examples in the Python docs. Do these examples work? If not, it may be that the

rabbitmq error when connect

余生长醉 提交于 2019-12-10 17:15:03
问题 i got this error when i try to connect using php-amqp: Fatal error: Class 'AMQPConnection' not found in $credentials =array('host' => 'localhost','port' => 5672); $cnn = new AMQPConnection($credentials); $cnn->connect(); 回答1: It looks like you don't have the AMQP PECL extension installed. That PECL extension is not a default part of PHP, so you'll need to compile and install it using the pecl tool. 来源: https://stackoverflow.com/questions/5424419/rabbitmq-error-when-connect

Confusion over how Java's Garbage Collector works (Nodes + Queue) [duplicate]

南楼画角 提交于 2019-12-10 17:11:53
问题 This question already has answers here : What is a NullPointerException, and how do I fix it? (12 answers) Closed 4 years ago . So I been trying to implement LinkedList, Stack, Queue in Java. For each one i'm using a node class such that, now I don't really want to discuss how my implementation is since I am aware there are better ways to do it, I just want to focus on my question. public class Node<E> { private E data; private Node<E> next; private Node<E> prev; public Node(E data) { this

Why is there no queue in Cocoa?

廉价感情. 提交于 2019-12-10 16:15:30
问题 I recently found out that there is no queue built into Cocoa (Touch, in this case). Why not? A queue is one of the most fundamental data structures in computer programming. I've seen some people suggesting the use of NSMutableArray , but this is extremely inefficient for pops/dequeues, because it requires removing the object at index 0. That will shift all of the elements down (towards the now empty entry), thus taking O(n) time for each remove operation. Am I missing something or was there