简体   繁体   English

Win32_Printer远程WMI查询真的很慢

[英]Win32_Printer remote WMI query really slow

I'm trying to update some information on some printers on a remote server. 我正在尝试更新远程服务器上某些打印机的某些信息。 I need to update stuff like location, comment and port. 我需要更新位置,评论和端口等内容。 I have a solution that works, but I find it very slow, and I was wondering if anyone have any idea of why. 我有一个有效的解决方案,但我发现它很慢,我想知道是否有人知道为什么。

I get the printer (and later the port) from the server through WMI with a code like this: (this is testing code) 我从服务器通过WMI获得打印机(以及后来的端口),代码如下:(这是测试代码)

var test = DateTime.Now;
ManagementScope scope3 = new ManagementScope("\\\\printserver\\root\\cimv2");
scope3.Connect();
SelectQuery q3 = new SelectQuery("select * from Win32_Printer WHERE Name = 'printername'");
ManagementObjectSearcher search3 = new ManagementObjectSearcher(scope3, q3);
var printers3 = search3.Get();
foreach(var p in printers3)
{
    //do stuff with printer here.
}
var test2 = DateTime.Now.Subtract(test).TotalSeconds;

When it is done test2 will contain "33.something" seconds. 完成后,test2将包含“33.something”秒。 If I do it without the where clause, it will take almost the same time. 如果我在没有where子句的情况下这样做,则几乎需要相同的时间。 Admittedly there are almost 1500 printers on this server, but I feel like I should be able to query for one specific printer in a faster way, and I do not understand why a query with a where clause on the name of the printer takes the same time as a "select all" query. 不可否认,这台服务器上有近1500台打印机,但我觉得我应该能够以更快的方式查询一台特定的打印机,而且我不明白为什么带有打印机名称的where子句的查询也是如此时间作为“全选”查询。

Any suggestions? 有什么建议?

-- -

Update 更新

As suggested below, I have tried to run the same query multiple times. 如下所示,我尝试多次运行相同的查询。 Still takes the same amount of time. 仍然需要相同的时间。 It just feels weird to me, that Windows would need to "touch" every single printer on the system, when I'm searching for a specific one. 我觉得很奇怪,当我在搜索特定的打印机时,Windows需要“触摸”系统上的每台打印机。

Admittedly there are almost 1500 printers on this server 不可否认,这台服务器上有近1500台打印机

That's the nasty little detail of course. 那当然是令人讨厌的小细节。 It takes 33 / 1500 = 0.022 seconds per printer. 每台打印机需要33/1500 = 0.022秒。 That's a pretty magic number in computers, about how long it takes to open a file on a spindle disk. 这在计算机中是一个非常神奇的数字,关于在主轴磁盘上打开文件需要多长时间。

There is a simple test you can perform to check if it is indeed the disk that's the bottleneck. 您可以执行一个简单的测试来检查它是否确实是作为瓶颈的磁盘。 Just run your query a second time, right after the slow one. 只需在慢速查询后再次运行查询。 File info will now be cached in the file system cache, it should execute in less than a second. 文件信息现在将缓存在文件系统缓存中,它应该在不到一秒的时间内执行。 You probably already did this, update your question with what you found out. 您可能已经这样做了,用您发现的内容更新您的问题。

Very little you can do about this in software of course. 当然,你在软件方面做的很少。 The server needs better hardware to keep you happy. 服务器需要更好的硬件才能让您满意。 An SSD is very nice, should speed this up by an easy factor of 20. Lots more RAM can help but is not the golden solution. SSD是非常好的,应该以20的简单因子加快速度。更多RAM可以帮助但不是黄金解决方案。 Poking the server more often so it keeps the file data in the cache is a workaround of sorts, not very friendly to the server. 更频繁地调用服务器以便将文件数据保存在缓存中是一种解决方法,对服务器不是很友好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM