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 ...
随机推荐
- IOS_UIButton去掉系统的按下高亮置灰效果
setAdjustsImageWhenHighlighted // default is YES. if YES, image is drawn darker when highlighted(p ...
- css clip样式 属性功能及作用
clip clip 在学前端的小伙伴前,估计是很少用到的,代码中也是很少看见的,但是,样式中有这样的代码,下面让我们来讲讲他吧! 这个我也做了很久的开发没碰到过这个属性,知道我在一个项目中,有一个功能 ...
- 使用fastDFS上传和下载图片文件
package com.xuecheng.test.fastdfs;import org.csource.common.MyException;import org.csource.fastdfs.* ...
- 【C/C++】BanGDream活动点数计算器
作为一个白嫖咸鱼,我每个活动都只打出三星卡就不玩了,于是写了一个模拟器,算算还要打几把hhh #include <iostream> #include <algorithm> ...
- 详解 Java I/O 与装饰者模式
1.I/O分类与装饰者模式 基本java I/O包含两种类型的流,字节流(inputStream.outputStream)与字符流(Writer,Reader),关于I/O操作类的设计,用到了装饰者 ...
- 团队协作项目——SVN的使用
参考文献:https://www.cnblogs.com/rwh871212/p/6955489.html 老师接了一个新项目,需要团队共同完成开发任务,因此需要SVN.SVN是C/S架构: 1.服务 ...
- python数据预处理和特性选择后列的映射
我们在用python进行机器学习建模时,首先需要对数据进行预处理然后进行特征工程,在这些过程中,数据的格式可能会发生变化,前几天我遇到过的问题就是: 对数据进行标准化.归一化.方差过滤的时候数据都从D ...
- 为什么Redis集群有16384个槽
一.前言 我在<那些年用过的Redis集群架构(含面试解析)>一文里提到过,现在redis集群架构,redis cluster用的会比较多. 如下图所示 对于客户端请求的key,根据公式H ...
- <转>企业应用架构 --- 分层
系统架构师-基础到企业应用架构-分层[上篇] 一.前言 大家好,接近一年的时间没有怎么书写博客了,一方面是工作上比较忙,同时生活上也步入正轨,事情比较繁多,目前总算是趋于稳定,可以有时间来完善以前没有 ...
- pf4j及pf4j-spring
什么是PF4J 一个插件框架,用于实现插件的动态加载,支持的插件格式(zip.jar). 核心组件 Plugin:是所有插件类型的基类.每个插件都被加载到一个单独的类加载器中以避免冲突. Plugin ...