powershell远程处理:非常慢
如果我从solaris服务器ssh到美国服务器,ssh连接速度非常快,比如删除一个文件很快就能完成。
但是为什么powershell远程处理这么慢,我进入远程会话后,然后删除一个项目,需要10多秒才能完成。
Enter-PSSession -computerName test
remove-item 'C:\20010101.xls'
运行以下命令也需要 5 秒以上。
[Environment]::UserDomainName + "\" + [Environment]::UserName+" on"+[Environment]::MachineName
我使用远程处理的原因之一是远程桌面连接速度很慢,因为它必须将大量数据从服务器传输到本地。对于远程处理,我希望它只传输数据量很少的文本,因此我预计它会比远程桌面连接快得多。但事实是它也很慢。
有什么方法可以提高性能,或者找出大部分时间都花在哪里了?
If I ssh from a solaris Server to a US server, the ssh connection is very fast, such as delete a file can complete very soon.
But why powershell remoting is so slowing, after I entered the remote session, and then remove an item, it takes more than 10 seconds to complete.
Enter-PSSession -computerName test
remove-item 'C:\20010101.xls'
running the following command also takess more than 5 seconds.
[Environment]::UserDomainName + "\" + [Environment]::UserName+" on"+[Environment]::MachineName
One of the reason I am using remoting is that remote desktop connection is slow as it has to transfer large amount of data from the server to local. And for remoting, I am hoping it only transfer text which is very little amount of data so I expect it will be much faster than remote desktop connection. But the fact is that it is also very slow.
Any way to enhance performance, or find out where most of the time goes to?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Daniel,
我猜您看到的大部分时间延迟是由于远程 PowerShell 会话的启动造成的。
尝试使用 Invoke-Command,而不是使用 Enter-PSSession。它仍然会初始化远程 PS 会话,但您不会获得所有控制台开销。
Invoke-Command -Computer test -ScriptBlock { [Environment]::UserDomainName + "\" + [Environment]::UserName+" on "+[Environment]::MachineName }
请记住,PowerShell 和WinRM 代表您做了很多事情,因为您的所有输出都被序列化为 XML,然后再次重组为对象。 PowerShell 最好的事情之一是,一切都是对象,这使得通过 ssh/bash/cmd 等执行类似操作时速度变慢。这都是关于权衡的。
当我正在做一些我知道需要一段时间的任务时,我会尝试将它们安排为工作,然后继续处理其他事情。
——格雷格
Daniel,
I'm guessing most of the time delay you're seeing is the due to the startup of the remote PowerShell session.
Rather than use Enter-PSSession try using Invoke-Command. It still initializes a remote PS session but you don't get all the console overhead.
Invoke-Command -Computer test -ScriptBlock { [Environment]::UserDomainName + "\" + [Environment]::UserName+" on "+[Environment]::MachineName }
Keep in mind that PowerShell and WinRM are doing a lot on your behalf because all your output is being serialized to XML and then reconstituted into objects again. One of the best things about PowerShell, everything is an object, is what makes it slower when performing similar actions via ssh/bash/cmd etc. It's all about the tradeoffs.
When I'm doing tasks that I know will take a while I try to schedule them as jobs and move on to other things.
--Greg