threadpool

Default values for System.Threading.ThreadPool.SetMaxThreads

别来无恙 提交于 2019-12-03 15:22:53
问题 Suppose, I don't set any values explicitly by calling the function: System.Threading.ThreadPool.SetMaxThreads What are the default values? 回答1: It depends on the .NET framework version, changed in 2.0, 3.0 and 4.0. In 2.0 it was 50 times the number of cores. In 3.0 (aka 2.0 SP1) it was 250 times the number of cores, 4.0 made it dynamic depending on bitness and OS resources. Max I/O completion threads was always 1000 if I remember correctly. In general, it is insanely high and a program should

Play Framework: What happens when requests exceeds the available threads

假装没事ソ 提交于 2019-12-03 15:05:21
I have one thread in the thread-pool servicing blocking request. def sync = Action { import Contexts.blockingPool Future { Thread.sleep(100) } Ok("Done") } In Contexts.blockingPool is configured as: custom-pool { fork-join-executor { parallelism-min = 1 parallelism-max = 1 } } In theory, if above request receives 100 simultaneous requests, the expected behaviour should be: 1 request should sleep(100) and rest of 99 requests should be rejected (or queued until timeout?). However I observed that extra worker threads are created to service rest of requests. I also observed that latency increases

Windows API Thread Pool simple example

℡╲_俬逩灬. 提交于 2019-12-03 14:11:35
[EDIT: thanks to MSalters answer and Raymond Chen's answer to InterlockedIncrement vs EnterCriticalSection/counter++/LeaveCriticalSection , the problem is solved and the code below is working properly. This should provide an interesting simple example of Thread Pool use in Windows] I don't manage to find a simple example of the following task. My program, for example, needs to increment the values in a huge std::vector by one, so I want to do that in parallel. It needs to do that a bunch of times across the lifetime of the program. I know how to do that using CreateThread at each call of the

When should a task be considered “long running”?

♀尐吖头ヾ 提交于 2019-12-03 13:44:45
问题 When working with tasks, a rule of thumb appears to be that the thread pool - typically used by e.g. invoking Task.Run() , or Parallel.Invoke() - should be used for relatively short operations. When working with long running operations, we are supposed to use the TaskCreationOptions.LongRunning flag in order to - as far as I understand it - avoid clogging the thread pool queue, i.e. to push work to a newly-created thread. But what exactly is a long running operation? How long is long, in

How to know if all the Thread Pool's thread are already done with its tasks?

萝らか妹 提交于 2019-12-03 13:33:18
I have this application that will recurse all folders in a given directory and look for PDF. If a PDF file is found, the application will count its pages using ITextSharp. I did this by using a thread to recursively scan all the folders for pdf, then if then PDF is found, this will be queued to the thread pool. The code looks like this: //spawn a thread to handle the processing of pdf on each folder. var th = new Thread(() => { pdfDirectories = Directory.GetDirectories(pdfPath); processDir(pdfDirectories); }); th.Start(); private void processDir(string[] dirs) { foreach (var dir in dirs) {

Migrate a single threaded app to multi-threaded, parallel execution, monte carlo simulation

主宰稳场 提交于 2019-12-03 12:45:53
I've been tasked with taking an existing single threaded monte carlo simulation and optimising it. This is a c# console app, no db access it loads data once from a csv file and writes it out at the end, so it's pretty much just CPU bound , also only uses about 50mb of memory. I've run it through Jetbrains dotTrace profiler. Of total execution time about 30% is generating uniform random numbers, 24% translating uniform random numbers to normally distributed random numbers. The basic algorithm is a whole lot of nested for loops , with random number calls and matrix multiplication at the centre,

Is there a way to ensure that threads are assigned to a specified set of objects?

丶灬走出姿态 提交于 2019-12-03 12:25:37
问题 We are working on an application where a set of objects can be affected by receiving messages from 3 different sources. Each message (from any of the sources) has a single object as its target. Each message receiver will be running on its own thread. We want the processing of the messages (after receiving), to be as high-speed as possible, so the message processing against the target objects will be done with another thread from a thread pool. The processing of the message will take longer

Java ExecutorService callback on thread terminate

坚强是说给别人听的谎言 提交于 2019-12-03 11:02:29
I am using cached thread pool ExecutorService to run some asynchronous background tasks. I've provided my ThreadFactory that hands out threads to the ExecutorService (whenever it needs them). My understanding of the cached thread pool is that after the thread is sitting idle for 60 seconds it is termniated by the ExecutorService. I want to perform some state cleanup when my thread is about to be terminated. What is the best way to achieve this? The ExecutorService does not readily provide hooks into the thread's lifecycle. I don't want to shutdown my ExecutorService - useful for running tasks

How to name the threads of a thread pool in Java [duplicate]

杀马特。学长 韩版系。学妹 提交于 2019-12-03 10:34:15
问题 This question already has answers here : Naming threads and thread-pools of ExecutorService (17 answers) Closed 3 years ago . I have a Java application that uses the Executor framework and I have code that looks like this protected ScheduledExecutorService scheduledExecutorService = new ScheduledThreadPoolExecutor(5) My understanding is that internally the JVM would create a pool of 5 threads. Now when I check the execution in a profiler, I get something like thread-pool2,thread-pool3 and so

How to debug a rare deadlock?

若如初见. 提交于 2019-12-03 10:21:29
I'm trying to debug a custom thread pool implementation that has rarely deadlocks. So I cannot use a debugger like gdb because I have click like 100 times "launch" debugger before having a deadlock. Currently, I'm running the threadpool test in an infinite loop in a shell script, but that means I cannot see variables and so on. I'm trying to std::cout data, but that slow down the thread and reduce the risk of deadlocks meaning that I can wait like 1hour with my infinite before getting messages. Then I don't get the error, and I need more messages, which means waiting one more hour... How to