参考:Max Degree of Parallelism最大并行度配置

结论:

  1. 与设置的线程数有关
  2. 有设置的并行度有关

测试如下:

@@@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();
@@#
  1. 不设置线程数,不限制并行数,每秒约9个

  1. 不使用并行,等到花都谢了

  1. 增加线程数,

不限制并行数

并行设为2

并行设为6

Parallel.ForEach 之 MaxDegreeOfParallelism的更多相关文章

  1. Parallel.ForEach 多线程 声明失败 "未将对象引用设置到对象的实例"

    x using System; using System.Collections.Generic; namespace Parallel.ForEach { class Program { //代码结 ...

  2. C# 多线程 Parallel.For 和 For 谁的效率高?那么 Parallel.ForEach 和 ForEach 呢?

    还是那句话:十年河东,十年河西,莫欺少年穷. 今天和大家探讨一个问题:Parallel.For 和 For 谁的效率高呢? 从CPU使用方面而言,Parallel.For 属于多线程范畴,可以开辟多个 ...

  3. Parallel.Foreach的基础知识

    微软的并行运算平台(Microsoft’s Parallel Computing Platform (PCP))提供了这样一个工具,让软件开发人员可以有效的使用多核提供的性能. Visual Stud ...

  4. Parallel.ForEach 使用多线遍历循环

    Parallel.ForEach相对于foreach是多线程,并行操作;foreach是单线程品德操作. static void Main(string[] args) { Console.Write ...

  5. 并行forearch的使用及测试(Parallel.Foreach)

    using System; using System.Collections.Generic; using System.Diagnostics; using System.Threading.Tas ...

  6. Parallel.Foreach

    随着多核时代的到来,并行开发越来越展示出它的强大威力! 使用并行程序,充分的利用系统资源,提高程序的性能.在.net 4.0中,微软给我们提供了一个新的命名空间:System.Threading.Ta ...

  7. [译]何时使用 Parallel.ForEach,何时使用 PLINQ

    原作者: Pamela Vagata, Parallel Computing Platform Group, Microsoft Corporation 原文pdf:http://download.c ...

  8. Parallel.ForEach , ThreadPool.QueueUserWorkItem

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  9. Parallel.ForEach() 并行循环

    现在的电脑几乎都是多核的,但在软件中并还没有跟上这个节奏,大多数软件还是采用传统的方式,并没有很好的发挥多核的优势. 微软的并行运算平台(Microsoft’s Parallel Computing ...

随机推荐

  1. DP-Burst Balloons

    leetcode312: https://leetcode.com/problems/burst-balloons/#/description Given n balloons, indexed fr ...

  2. 转 MessageDigest来实现数据加密

    转自 https://www.cnblogs.com/androidsuperman/p/10296668.html MessageDigest MessageDigest 类为应用程序提供信息摘要算 ...

  3. Mysql的索引调优详解:如何去创建索引以及避免索引失效

    在正式介绍Mysql调优之前,先补充mysql的两种引擎 mysql逻辑分层 InnoDB:事务优先(适合高并发操作,行锁) MyISAM:性能优先(表锁) 查看使用的引擎: show variabl ...

  4. shell脚本 查看cpu的温度

    一.简介 源码地址 日期:2018/8/24 介绍:查看主板上单个多核CPU中温度最高的一个内核 效果图: 二.使用 适用:centos6+ 语言:英文 注意:需要先安装lm_sensors,不支持虚 ...

  5. shell脚本 双向登陆免密

    一.简介 源码地址 日期:2018/4/23 介绍:用于hadoop的双向免密脚本,让填写机器互相之间免密登陆 效果图: 暂无 二.使用 适用:centos6+ 语言:中文 注意:执行前需要填写脚本里 ...

  6. [BUUCTF]PWN——0ctf_2017_babyheap

    0ctf_2017_babyheap 附件 步骤: 例行检查,64位程序,保护全开 本地试运行一下,看看大概的情况,经典的堆题的菜单 main函数 add() edit() delete() show ...

  7. 小迪安全 Web安全 基础入门 - 第十天 - 信息打点-APP&小程序篇&抓包封包&XP框架&反编译&资产提取

    一.本节知识点思维导图 二.APP-外在资产收集 1.将APP安装在模拟器中,修改模拟器代理设置,使用Fiddler.Burpsuite.Charles等抓包工具抓取APP访问的http协议数据包,抓 ...

  8. CF1092B Teams Forming 题解

    Content 有 \(n\) 个学生,每个学生有一个能力值 \(a_i\).现在想把学生两两分成一组,但是不能让每个组里面的学生能力值不相同,因此可以通过刷题来提升自己的能力值,每次解出一道题,能力 ...

  9. 后端调用WebApi

    using System;using System.Collections.Generic;using System.Linq;using System.Net.Http;using System.W ...

  10. xml数据结构处理

    <data> <country name="Liechtenstein"> <rank updated="yes">2< ...