c# - Recursion and Rx parallelism -


While trying to cross the tree tree efficiently, I tried the described Rx solution. Although this solution works for the depth of the small tree, but it is not usable to the depth of the big tree.

  Public static zero TestTreeTraversal () {Func & lt; DirectoryInfo, IObservable & lt ;, the default scheduler creates too many threads, slowing the paste traversal.  

DirectoryInfo & gt; & Gt; Recurse = null; Recurse = i = & gt; Overview (return). Return (i) .Cockets (i.GetDirInfos (.) ToObservable (.) SelectMany (D = & recurse (d)). ObserveOld (Scheduler); Var obs = recurse (New Directory Info (@ "C: \ ")); Var Results = obs.ToEnumerable (). ToList ();} Public Fixed IEnumerable GetDirInfos {This DirectoryInfo Dior} {IEnumerable & lt; DirectoryInfo> Dirs = null; Try { Dirs = dir.EnumerateDirectories ("*", SearchOption.TopDirectoryOnly);} hold (exception) {yield break;} foreach (dirs in directory info d) yield returns d;}

ObserveOn (Scheduler.Default) is removed, then the comparison of the function mono-threaded recursive function Works at the same speed in. Using inspection, it appears that each time the selector is slowed down dramatically, the selector is made every time.

Is the scheduler a Can only control / limit the maximum number of times?

Is there another way to write such a parallel tree translate with RX, without falling into this parallel pit?

This can be done in RX, possibly by passing by environment. Calculate the processor in the maxConcurrent parameter.

However, RX originally provided IObservable & lt; for asynchronous processing. T & gt; is designed to work on. Of course, you can see a IEnumerable & lt; T & gt; to be a IObservable & lt; T & gt; and process it on parallel, as you have done here, but it is against the grain in RX.

There is a more natural solution to this problem, which is IEnumerable & lt; T & gt; and is designed to split a query into parallel processes, physical processor is available keeping in mind the number of accounts contained in it.

The RX is about the majority fusion, while PLINQ is mostly about submitting it.

Unchecked :

  function & lt; DirectoryInfo, ParallelQuery & lt; DirectoryInfo & gt; & Gt; Recurse = null; Recurse = dir = & gt; New [] {dir}. Asperal (.) Koncat (DIR Gatedar Infos (). Asperrel (.) SelectionMonny (Rickers)); Var result = records (new directoryInfo (@ "C: \")). ToList ();  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -