我写了一个简单的程序,通过侦听指定的端口来打开端口范围。 我注意到,这个程序需要不同的时间在Windows和Linux上打开从端口1到端口65535的所有端口。
在Linux上,大约需要2秒钟打开所有的端口。 在Windows上,它接近半小时(我没有测量确切的分钟数,因为我从来没有等待完成)。
在这方面,Windows客观上是比较慢的,如果是的话,为什么我可以做任何事情来让它运行得更快?
请注意,虽然testing运行在非常不同的硬件上,但考虑到时序在数量级上有所不同,可能并不重要。
当不同的用户时,远程registry总是空
使用ServiceController类与Windows Service进行通信
2 AverageTimer32性能计数器
插入位置/位置在任何应用程序内
// This is a very basic TCP port listener that allows you to listen on a port range // If you run this program outside of firewall and run a port scanner inside a firewall // pointing to the ip address where this program runs,the port scanner will be able you // to tell which exactly ports are open on the firewall // This code will run on Windows,but most importantly also on linux. // DigitalOcean.com has all ports for their VMs open by default. So spin a new VM,// copy pln.cs in your (root) home folder and then run: // sudo apt-get update // sudo apt-get install mono-complete -y // mcs pln.cs // ulimit -n 66000 // ./pln.exe 1 65535 // Now you can use the VM ip address to determine open ports on your firewall // Note that this is a dev utility,and is aimed to be minimal - no input validation,// no error handling. In case of a error stack trace is dumpled to console using System; using System.Net; using System.Net.sockets; namespace PortListener { class Program { static void Main(string[] args) { try { Console.WriteLine("Usage: pln.exe startPort [endPort]"); Listen(args); } catch (Exception ex) { Console.WriteLine("Error: " + ex); } } private static void Listen(string[] args) { int startPort = int.Parse(args[0]); int endPort = int.Parse(args[1]); Console.WriteLine("Started binding..."); for (int i = startPort; i <= endPort; i++) { if (i % 100 == 0 && Environment.Osversion.Platform != PlatformID.Unix) { Console.WriteLine("Binding port " + i); } TcpListener listener = new TcpListener(IPAddress.Any,i); try { listener.Start(); } catch (SocketException ex) { if (ex.socketErrorCode == SocketError.AddressAlreadyInUse) { Console.WriteLine("Port " + i.ToString() + " already in use"); continue; } if (ex.socketErrorCode == SocketError.AccessDenied) { Console.WriteLine("Access denied to port " + i.ToString()); continue; } throw; } listener.BeginAcceptSocket(DoAcceptSocketCallback,listener); } Console.WriteLine("Finished binding. Ctrl-C to stop."); Console.ReadLine(); } private static void DoAcceptSocketCallback(IAsyncResult ar) { TcpListener listener = (TcpListener) ar.AsyncState; listener.EndAcceptSocket(ar).Close(); Console.WriteLine("Connection on port " + ((IPEndPoint) listener.LocalEndpoint).Port.ToString()); listener.BeginAcceptSocket(DoAcceptSocketCallback,listener); } } }
更新1 ,所以这显然与.net无关。 如果我们捕获这里或这里描述的诊断跟踪,我们将看到如下所示:
这告诉我们,winsock listen call需要400毫秒的时间。 任何想法为什么?
这个问题描述了类似的问题,有些人可以重现,有些人不能。 我的猜测是,它取决于Windows / SP版本。 我正在运行Windows 10 。 很久以前,半开放的networking连接出现了一个限速问题,导致了很多人的悲痛,因为他们无法有效运作。 这可能是由类似的东西造成的,尽pipe看起来这不像是与旧的问题有关。
更新2 – 在Windows 7机器上testing,并且工作速度非常快(与linux时序相当)。 显然有些事情从那以后发生了变化?
如何测量用于.NET远程处理的IP端口的进/出字节数?
在同一个进程中,在AppDomain之间发送大的字节数组
.NET Framework依赖于Windows API有多less?
从PowerShell挂起或hibernate
在iis中的IP地址和域名限制通过PowerShell
嗯是的。 坏司机。
没有延迟的电脑和没有延迟的电脑之间的区别在于没有延迟的电脑没有安装大量的废话。
下载一个工具,可以查看安装的驱动程序,并试图猜测哪些是造成放缓。 您可以使用sysinternals套件(参见驱动程序选项卡)或Nirsofts DriverView或InstalledDriversList中的 Autoruns 。
如果您使用后者,请按组列列出驱动程序列表,并查看Ndis和/或网络。 这很可能是其中之一。
所以当我开始的时候,我测量了在我的机器上打开1到10000的端口需要多长时间。 然后,我一个接一个地去掉司机,再次进行测量。 结果如下:
All Crap installed - 226 seconds Same as above but removed Networx Traffic monitor - 9 seconds Same as above but removed TeamViewer remote assistance - 7 seconds Same as above but removed Checkpoint VPN client - 0 seconds
请注意,只是关闭这些程序不会帮助。 司机需要被删除/禁用,看到一个改进。
所以没有必要责怪Windows。 有很多其他的软件供应商可供选择;)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。