视频下载为小于1毫秒

视频下载为小于1毫秒

本文介绍了视频下载为小于1毫秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要调用线程睡眠少于1毫秒。在网上我红,无论是视频下载也没有Windows的操作系统的支持。

I want to call thread sleep with less than 1 millisecond.On the net I red that neither thread.Sleep nor Windows-OS support that.

什么是该解决方案?

对于所有的谁不知道为什么,我需要这样的:我做了压力测试,并想知道有多少邮件我的模块,每秒能够处理。所以,我的code是:

For all the who wonder why I need this:I'm doing a stress test, and want to know how many messages my module can handle per second.So my code is:

 // Set the relative part of Second hat will be allocated for each message
 //For example: 5 messages - every message will get 200 miliseconds
 var quantum = 1000 / numOfMessages;

 for (var i = 0; i < numOfMessages; i++)
 {
      _bus.Publish(new MyMessage());
      if (rate != 0)
          Thread.Sleep(quantum);
 }

我会很高兴得到您的意见了。

I'll be glad to get your opinion on that.

推荐答案

您无法做到这一点。一个单一的睡眠调用通常会远远超过一毫秒块(它的操作系统和系统相关的,但在我的经验,的Thread.Sleep(1)趋于阻塞介于12-15ms)。

You can't do this. A single sleep call will typically block for far longer than a millisecond (it's OS and system dependent, but in my experience, Thread.Sleep(1) tends to block for somewhere between 12-15ms).

视窗,一般来说,没有被设计为实时操作系统的。这种类型的控制的通常是不可能实现的Windows正常(台式机/服务器)的版本。

Windows, in general, is not designed as a real-time operating system. This type of control is typically impossible to achieve on normal (desktop/server) versions of Windows.

你可以得到的最接近的是典型的旋转,吃CPU周期,直到你达到你想要的等待时间(与高性能计数器测量)。然而,这是pretty的可怕 - 你吃了一个完整的CPU,即使如此,你可能会得到的通过操作系统的时间和有效的休眠的时间超过1ms的...

The closest you can get is typically to spin and eat CPU cycles until you've achieved the wait time you want (measured with a high performance counter). This, however, is pretty awful - you'll eat up an entire CPU, and even then, you'll likely get preempted by the OS at times and effectively "sleep" for longer than 1ms...

这篇关于视频下载为小于1毫秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 00:32