我如何运行最大值。并行线程的最大输出 [英] How do I run maximum no. of parallel threads for maximum output
问题描述
我编写了一个应用程序来查看我们如何使用任务。
我一次启动50000个任务,最小线程池设置为32500(这是64位应用程序的限制)并在睡眠时间为5秒的函数中将记录插入数据库。
如果我设置分钟。线程池到8000线程它正在写15-16k记录/分钟。
但是增加了没有。它减少到2-3k的线程。
我无法确定这种减少的原因。
i已经在vs 2012 .net 4.5中构建了应用程序。
这可能是什么原因?
.net或windows中是否存在其他限制或某些硬件相关问题。
static void Main(string [] args)
{
int minThread = 32500;
ThreadPool.SetMaxThreads(Int32.MaxValue,Int32.MaxValue);
ThreadPool.SetMaxThreads(minThread,minThread);
Start();
}
static void Start()
{
int count = 50000;
任务[] taskArray = new Task [count];
for(int i = 0; i< taskArray.Length; i ++)
{
Task task1 = null;
task1 = Task.Factory.StartNew(()=> function());
taskArray [i] = task1;
}
Task.WaitAll(taskArray);
}
static void function()
{
do
{
Thread.Sleep(5000);
使用(TestEntities db = new TestEntities())
{
Reponse res = new Reponse {datetime = DateTime.Now,message = Thread.CurrentThread.ManagedThreadId.ToString()};
db.Reponses.Add(res);
db.SaveChanges();
}
}
while(true);
}
原因有很多:
1)你使用什么db以及该引擎的性能特征。
2)你的线程/任务之间的资源/对象争用
3)保存的数据量
作为旁注,我的 RaptorDB - Key Value Store V2 [ ^ ]可以在i7系统上处理400,000次写入/秒,因此如果您真的需要高吞吐量写入,那么可以考虑一下。
I have written an application to see how we can use tasks.
I am starting 50000 tasks in one go with minimum thread pool set to 32500 ( which is the limit for a 64 bit application) and inserting a record into db in the function with a sleep of 5 sec.
If I set the min. thread pool to 8000 threads it is writing 15-16k records/minute.
But on increasing the no. of threads it reduces to 2-3k.
I am not able to pinpoint for the reason for this reduce.
i have built the app in vs 2012 .net 4.5.
What can be the reason for this?
Whether there is some other limit in .net or windows or some hardware related issue.
static void Main(string[] args) { int minThread = 32500; ThreadPool.SetMaxThreads(Int32.MaxValue, Int32.MaxValue); ThreadPool.SetMaxThreads(minThread, minThread); Start(); } static void Start() { int count =50000 ; Task[] taskArray = new Task[count]; for (int i = 0; i < taskArray.Length; i++) { Task task1 = null; task1 = Task.Factory.StartNew(() => function()); taskArray[i] = task1; } Task.WaitAll(taskArray); } static void function() { do { Thread.Sleep(5000); using (TestEntities db = new TestEntities()) { Reponse res = new Reponse { datetime = DateTime.Now, message = Thread.CurrentThread.ManagedThreadId.ToString() }; db.Reponses.Add(res); db.SaveChanges(); } } while (true); }
There are many reasons:
1) What "db" are you using and the performance characteristics of that engine.
2) Resource/object contention between your threads/tasks
3) The amount of data being saved
As a side note my RaptorDB - The Key Value Store V2[^] can handle 400,000 writes/sec on an i7 system, so that is some thing to think about if you really need high throughput writes.
这篇关于我如何运行最大值。并行线程的最大输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!