Parallel.ForEach 之 MaxDegreeOfParallelism
参考:Max Degree of Parallelism最大并行度配置
结论:
- 与设置的线程数有关
- 有设置的并行度有关
测试如下:
@@@code
System.Threading.ThreadPool.SetMinThreads(20, 20);
System.Threading.ThreadPool.SetMinThreads(50, 50); var list = GetIPByMask(IPAddress.Parse("192.168.10.1"), IPAddress.Parse("255.255.255.0"));
System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
stopwatch.Start();
Parallel.ForEach(list, new ParallelOptions() { MaxDegreeOfParallelism=6}, a =>
{ var status = Ping(a.ToString(), (ip, ex) => Console.WriteLine($"ping {ip},{ex.Message}"), 1000);
Console.WriteLine($"at {DateTime.Now.Second} ping {a.ToString()}
{status.ToString()}");
}
); //foreach (var a in list) //{ // var status = Ping(a.ToString(), (ip, ex) => Console.WriteLine($"ping {ip},{ex.Message}"), 1000); // Console.WriteLine($"at {DateTime.Now.Second} ping {a.ToString()} {status.ToString()}"); //}
Console.WriteLine($"平均每秒处理:{(int)Math.Ceiling( list.Count/stopwatch.Elapsed.TotalSeconds)}" );
Console.Read();
@@#
- 不设置线程数,不限制并行数,每秒约9个
- 不使用并行,等到花都谢了
- 增加线程数,
不限制并行数
并行设为2
并行设为6
Parallel.ForEach 之 MaxDegreeOfParallelism的更多相关文章
- Parallel.ForEach 多线程 声明失败 "未将对象引用设置到对象的实例"
x using System; using System.Collections.Generic; namespace Parallel.ForEach { class Program { //代码结 ...
- C# 多线程 Parallel.For 和 For 谁的效率高?那么 Parallel.ForEach 和 ForEach 呢?
还是那句话:十年河东,十年河西,莫欺少年穷. 今天和大家探讨一个问题:Parallel.For 和 For 谁的效率高呢? 从CPU使用方面而言,Parallel.For 属于多线程范畴,可以开辟多个 ...
- Parallel.Foreach的基础知识
微软的并行运算平台(Microsoft’s Parallel Computing Platform (PCP))提供了这样一个工具,让软件开发人员可以有效的使用多核提供的性能. Visual Stud ...
- Parallel.ForEach 使用多线遍历循环
Parallel.ForEach相对于foreach是多线程,并行操作;foreach是单线程品德操作. static void Main(string[] args) { Console.Write ...
- 并行forearch的使用及测试(Parallel.Foreach)
using System; using System.Collections.Generic; using System.Diagnostics; using System.Threading.Tas ...
- Parallel.Foreach
随着多核时代的到来,并行开发越来越展示出它的强大威力! 使用并行程序,充分的利用系统资源,提高程序的性能.在.net 4.0中,微软给我们提供了一个新的命名空间:System.Threading.Ta ...
- [译]何时使用 Parallel.ForEach,何时使用 PLINQ
原作者: Pamela Vagata, Parallel Computing Platform Group, Microsoft Corporation 原文pdf:http://download.c ...
- Parallel.ForEach , ThreadPool.QueueUserWorkItem
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- Parallel.ForEach() 并行循环
现在的电脑几乎都是多核的,但在软件中并还没有跟上这个节奏,大多数软件还是采用传统的方式,并没有很好的发挥多核的优势. 微软的并行运算平台(Microsoft’s Parallel Computing ...
随机推荐
- swift 实现QQ好友列表功能
最近项目中有类似QQ好友列表功能,整理了一下,话不多说,直接上代码 import UIKit class QQFriend: NSObject { var name: String? var intr ...
- spring注解事务管理
使用步骤: 步骤一.在spring配置文件中引入<tx:>命名空间<beans xmlns="http://www.springframework.org/schema/b ...
- PHP之CURL实现含有验证码的模拟登录
博主最近在为学校社团写一个模拟登录教务系统来进行成绩查询的功能,语言当然是使用PHP啦,原理是通过php数据传输神器---curl扩展,向学校教务系统发送请求,通过模拟登录,获取指定url下的内容. ...
- 【MySQL】学生成绩
统计每个人的总成绩排名 select stu.`name`,sum(stu.score) as totalscore from stu GROUP BY `name` order by totalsc ...
- 【科研工具】MathType7.2的安装破解与使用
亲测可用,可以嵌入word. [我们为什么要用MathType] tex不香嘛,但是学校给的模板只有word,word输入公式点起来实在是太麻烦了. 有了这个就可以直接输入公式转换啦. [安装破解教程 ...
- 【Xcode】sh: pause: command not found
system("pause"); 只适合于DOS和Windows系统,不适合Linux系统. 直接删掉就可以. 或者改为: #include <unistd.h> pa ...
- Anaconda+pycharm(jupyter lab)搭建环境
之前先是安装了pycharm,手动安装了python2.7和3.7版本,在pycharm里面使用alt+/手动下载包.后来想使用jupyter lab,手动下载包太麻烦且有版本管理的文艺,于是打算装A ...
- 【Git】【Gitee】通过git远程删除仓库文件
安装Git Git安装配置-菜鸟教程 没有安装下载的,请读者自行安装下载. 启动与初步配置 配置用户名与邮箱 git config --global user.name "用户名" ...
- 为什么Redis集群有16384个槽
一.前言 我在<那些年用过的Redis集群架构(含面试解析)>一文里提到过,现在redis集群架构,redis cluster用的会比较多. 如下图所示 对于客户端请求的key,根据公式H ...
- 万字教你如何用 Python 实现线性规划
摘要:线性规划是一组数学和计算工具,可让您找到该系统的特定解,该解对应于某些其他线性函数的最大值或最小值. 本文分享自华为云社区<实践线性规划:使用 Python 进行优化>,作者: Yu ...