This completes in 2.3 minutes on LOCALSERVER:
A: measure-command {$x = invoke-command {gci -recurse "C:\"}}
This completes in 38.4 minutes on LOCALSERVER:
B: measure-command {$x = invoke-command -comp LOCALSERVER {gci -recurse "C:\"}}
Why is B so much slower? Is it because the "output is being serialized to XML and then reconstituted into objects again", as explained here, with B but not A? Or is something else going on?
LOCALSERVER runs Windows 2008R2 with PS v3. In both cases $x.count
is 98973.
I was wondering about changing an existing script to use PSRemoting for file searches on remote servers. I thought the searches might finish sooner with gci running on the remote target. In a handful of tests, the searches actually ran much longer with PSRemoting. I'm asking about the loopback scenario only because it seemed like the simplest case; I saw similar results with remote servers. So I'll stick with UNC path searches like this:
gci -recurse \\REMOTESERVER\C$\folder
...unless these results seem odd, and some adjustment to my remoting configuration or syntax might offer a big performance boost?
As you mentioned, the time required to invoke the command remotely must also take into account the time needed to deserialize any given object you return from your remote pipeline (in your case the whole tree of FileSystemInfo of the C drive). I would suggest to limit the number of objects you serialize and deserialize over the network and, while comparing performances of your servers, perhaps consider the time taken from within the machine you are running the code on:
Invoke-Command -comp LOCALSERVER { Measure-Command { gci -recurse "C:\" } }
Somewhere in between returning full objects and just getting a string list, if the remote system is running V3, you can get a shallow deserialization via json:
ConvertFrom-Json (icm -comp server { gci -rec c:\ | convertto-json -Depth 1})
Edit:
Converting to/from csv gets you a (shallow) deserialized object, and actuall seems to run faster than out-string:
ConvertFrom-csv (icm -comp server { gci -rec c:\ | convertto-csv})
Yes, you're correct about the overhead of serializing/deserializing the FileInfo
and DirectoryInfo
objects over the wire. If you don't care about getting real objects, do something like this:
icm -comp server { gci -rec c:\ | out-string }
It should be an order of magnitude faster, at least.
来源:https://stackoverflow.com/questions/16092778/psremoting-performance-overhead-with-get-childitem