threadpool

Server 2008 RC2, IIS 7.5, ASP.NET and Requests Queued Poor Performance

点点圈 提交于 2019-12-03 07:26:07
问题 I already know the answer to this, but wanted to share with the community since it is NOT documented from Microsoft. The scenario: A surge of traffic hits your IIS 7.5 ASP.NET website, and you notice that requests start queuing up. The performance of the site slows to a crawl, yet you have plenty of CPU and RAM available. This is the problem we saw recently with a site that made a bunch of internal web-service calls. An internal health check would start timing-out, which would cause this

Optimal way of creating a fixed size thread pool in Java using the Executors service

ぃ、小莉子 提交于 2019-12-03 06:59:45
I am using the Executors framework in Java to create thread pools for a multi-threaded application, and I have a question related to performance. I have an application which can work in realtime or non-realtime mode. In case it's realtime, I'm simply using the following: THREAD_POOL = Executors.newCachedThreadPool(); But in case it's not realtime, I want the ability to control the size of my thread pool. To do this, I'm thinking about 2 options, but I don't really understand the difference, and which one would perform better. Option 1 is to use the simple way: THREAD_POOL = Executors

Java - relationship between threads and CPUs

Deadly 提交于 2019-12-03 06:58:48
I am pretty new to multithreading, and I am working on a project where I am trying to utilize 4 CPUs in my Java program. I wanted to do something like int numProcessors = Runtime.getRuntime().availableProcessors(); ExecutorService e = Executors.newFixedThreadPool(numProcessors); Will this guarantee that I will have one thread working per CPU? At the time that I create the threads, the system will not be busy, however some time afterwards it will be extremely busy. I thought that the OS will pick the least busy CPU to create the threads, but how does it work if none of them are particularly

Java 8 parallel stream and ThreadLocal

守給你的承諾、 提交于 2019-12-03 06:57:32
问题 I am trying to figure out how can I copy a ThreadLocal value in Java 8 parallel stream. So if we consider this: public class ThreadLocalTest { public static void main(String[] args) { ThreadContext.set("MAIN"); System.out.printf("Main Thread: %s\n", ThreadContext.get()); IntStream.range(0,8).boxed().parallel().forEach(n -> { System.out.printf("Parallel Consumer - %d: %s\n", n, ThreadContext.get()); }); } private static class ThreadContext { private static ThreadLocal<String> val = ThreadLocal

Which ThreadPool in Java should I use?

寵の児 提交于 2019-12-03 06:48:06
There are a huge amount of tasks. Each task is belong to a single group. The requirement is each group of tasks should executed serially just like executed in a single thread and the throughput should be maximized in a multi-core (or multi-cpu) environment. Note: there are also a huge amount of groups that is proportional to the number of tasks. The naive solution is using ThreadPoolExecutor and synchronize (or lock). However, threads would block each other and the throughput is not maximized. Any better idea? Or is there exist a third party library satisfy the requirement? A simple approach

Default values for System.Threading.ThreadPool.SetMaxThreads

邮差的信 提交于 2019-12-03 05:52:10
Suppose, I don't set any values explicitly by calling the function: System.Threading.ThreadPool.SetMaxThreads What are the default values? 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 never get close. On a 32-bit machine, the program is pretty likely to bomb with OOM first when all of those

Async-Await vs ThreadPool vs MultiThreading on High-Performance Sockets (C10k Solutions?)

為{幸葍}努か 提交于 2019-12-03 05:23:52
问题 I'm really confused about async-await s, pool s and thread s. The main problem starts with this question: "What can I do when I have to handle 10k socket I/O?" (aka The C10k Problem). First, I tried to make a custom pooling architecture with threads that uses one main Queue and multiple Thread s to process all incoming datas. It was a great experience about understanding thread-safety and multi-threading but thread is an overkill with async-await nowadays. Later, I implemented a simple

Clarification on thread pool max threads

大憨熊 提交于 2019-12-03 05:02:55
问题 I've read here that : In v2.0, 3.5, and 4.0, ASP.NET initializes the CLR ThreadPool with 100 threads per processor(core) That is correct , I checked it ( I have 8 core machine , so 8*100 = 800 ): But then I saw this and this: maxWorkerThreads — Configures the maximum number of worker threads to use for the process on a per-CPU basis.The range for this attribute is from 5 through 100. The default is 20 . Question I don't see how the numbers fits in here : The first paragraph states that I have

When should a task be considered “long running”?

久未见 提交于 2019-12-03 03:41:21
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 terms of time? Are there other factors besides the expected task duration to be considered when deciding

使用线程池+内存队列实现异步处理业务问题

。_饼干妹妹 提交于 2019-12-03 02:43:45
背景 当系统中的业务存在大量的相同任务(比如发送大量邮件),并且每个任务花费的时间也比较长,前端需要较快 的响应,针对这种需求,我们可以采用消息队列进行异步通知,同时也可以采用线程池+内存队列实现异步通知,处理业务问题。 代码实现 以下采用发送邮件作为demo 邮箱实体类 @Data public class Email implements Serializable { private static final long serialVersionUID = 1L; /** * 自增主键 */ private Long id; /** * 接收人邮箱(多个逗号分开) */ private String receiveEmail; /** * 主题 */ private String subject; /** * 发送内容 */ private String content; /** * 模板 */ private String template; /** * 发送时间 */ private Timestamp sendTime; } 邮件队列 public class MailQueue { //队列大小 static final int QUEUE_MAX_SIZE = 1000; static BlockingQueue<Email> blockingQueue = new