PLINQ进行AsParallel()与低优先级? [英] PLINQ AsParallel() with lower priority?

查看:149
本文介绍了PLINQ进行AsParallel()与低优先级?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是它可以运行一些我PLINQ进行AsParallel() - 以较低的优先级比其他人查询? (或一些具有较高优先级比其他) 这可能与PLINQ或我必须避免PLINQ,做所有的东西我自己?

is it possible to run some of my PLINQ AsParallel() - Queries with a lower priority than others? (Or some with a higher priority than others) Is this possible with PLinq or will I have to avoid PLINQ and do all the stuff on my own?

编辑/ UPDATE:

EDIT/UPDATE:

有没有可能叫

Thread.Sleep(0)

当我要存档较低的优先级执行的并行算法里面? 或者是一个非常不好的做法/破解?

inside the parallel executed method when I want to archive a lower priority? Or is that a very bad practice/hack?

推荐答案

不幸的是,这是不能直接在PLINQ。

Unfortunately, this is not directly possible in PLINQ.

您可以通过创建一个自定义的的TaskScheduler 。这将让你有定制的优先级时,使用的Parallel.For 的ForEach

You can do it in most of the rest of the Task Parallel Library via creation of a custom TaskScheduler. This would allow you to have custom "priorities" when using Parallel.For or ForEach.

但是,没有提供自定义的TaskScheduler能力与PLINQ,因为PLINQ需要从的TaskScheduler非常严格的保证,而担心的是揭露这将是很成问题。

However, the ability to customize the TaskScheduler was not provided with PLINQ, since PLINQ requires very strict guarantees from the TaskScheduler, and the fear was that exposing this would be very problematic.

编辑/ UPDATE:

EDIT/UPDATE:

有没有可能叫

的Thread.Sleep(0)

Thread.Sleep(0)

这会低的优先级,但不幸的是,有它自己的问题,尤其是在与PLINQ相结合。这将有可能导致线程不足的线程池,因为你会在线程池线程沉睡。

This would "lower" the priority, but unfortunately, has it's own issues, especially when combined with PLINQ. This will potentially cause thread starvation in the ThreadPool, since you'll be "sleeping" on ThreadPool threads.

在此外,有一个与这个一个根本问题 - PLINQ被设计并打算用于处理的查询的,并且没有被设计用于处理的。引入逻辑code,控制流结构是真正针对PLINQ背后的理论,很可能会导致意想不到的性能影响您不希望,特别是如果你使用的是默认的分区。

In addition, there's a fundamental problem with this - PLINQ is designed and intended to handle queries, and is not designed for processing. Introducing logical code to control the flow structure is really against the theory behind PLINQ, and will likely cause unintended performance repercussions you aren't expecting, especially if you're using the default partitioning.

这篇关于PLINQ进行AsParallel()与低优先级?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆