<p dir="ltr">erl +A0 to turn off async filé access?<br>
Or isn’t that used for list dir and filé info?<br>
</p>
<br><div class="gmail_quote"><div dir="ltr">Den lör 10 dec 2016 18:33Frank Muller <<a href="mailto:frank.muller.erl@gmail.com">frank.muller.erl@gmail.com</a>> skrev:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_msg"><font face="UICTFontTextStyleBody" class="gmail_msg"><span class="gmail_msg">All in one file:</span></font><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg"></span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">-module(dir).</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg"></span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">-include_lib("kernel/include/file.hrl").</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg"></span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">-export([ walker/1,</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">         walker1/1,</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">         walker2/1 ]).</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg"></span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">%% original</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">walker(Path) -></span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">   %% io:format("~s~n", [Path]),</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">   case file:read_file_info(Path) of</span></div><div class="gmail_msg"><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">       {ok, #file_info{type = regular}} -></span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">           1;</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"></div><div class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">       _ -> %% not care about symlink for nor, assume a directory</span></div><div class="gmail_msg"><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">           Children = filelib:wildcard(Path ++ "/*"),</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">           lists:foldl(fun(P, N) -> N + walker(P) end, 0, Children)</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">   end.</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg"></span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"></div><div class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">%% Sergej version + [raw] option</span></div><div class="gmail_msg"><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">walker1(Path) -></span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">   case prim_file:list_dir(Path) of</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">       {ok,L} -></span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">           walker1(Path,L,0);</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">       _ -></span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">           0</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">   end.</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">walker1(Pth,["."|T],Sz) -></span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">   walker1(Pth,T,Sz);</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">walker1(Pth,[".."|T],Sz) -></span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">   walker1(Pth,T,Sz);</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">walker1(Pth,[H|T],Sz) -></span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">   Nm = Pth++"/"++H,</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"></div><div class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">   case prim_file:read_file_info(Nm, [raw]) of</span></div><div class="gmail_msg"><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">       {ok,#file_info{type = regular, size = FS}} -></span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">           walker1(Pth,T,Sz+FS);</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">       {ok,#file_info{type = directory}} -></span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">       case prim_file:list_dir(Nm) of</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">               {ok,L} -></span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">                   walker1(Pth, T, walker1(Nm,L,Sz));</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">               _ -></span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">                   walker1(Pth, T, Sz)</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">           end;</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">       _ -></span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">           walker1(Pth,T,Sz)</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">   end;</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">walker1(_,[],Sz) -></span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">   Sz.</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg"></span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg"></span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg"></span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"></div><div class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">%% Sergej version + Max's hint</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">walker2(Path) -></span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">   {ok, Port} = prim_file:start(),</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">   case prim_file:list_dir(Port, Path) of</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">       {ok,L} -></span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">           walker2(Port,Path,L,0);</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">       _ -></span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">           0</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">   end.</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg"></span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">walker2(Port,Pth,["."|T],Sz) -></span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">   walker2(Port,Pth,T,Sz);</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">walker2(Port,Pth,[".."|T],Sz) -></span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">   walker2(Port,Pth,T,Sz);</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">walker2(Port,Pth,[H|T],Sz) -></span></div><div class="gmail_msg"><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">   Nm = Pth++"/"++H,</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"></div><div class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">   case prim_file:read_file_info(Nm, [raw]) of</span></div><div class="gmail_msg"><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">       {ok,#file_info{type = regular, size = FS}} -></span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"></div><div class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">           walker2(Port,Pth,T,Sz+FS);</span></div><div class="gmail_msg"><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">       {ok,#file_info{type = directory}} -></span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"></div><div class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">           case prim_file:list_dir(Port,Nm) of</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">               {ok,L} -></span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">                   walker2(Port,Pth,T,walker2(Port,Nm,L,Sz));</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">               _ -></span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">                   walker2(Port,Pth, T, Sz)</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">           end;</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">       _ -></span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">           walker2(Port,Pth,T,Sz)</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">   end;</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">walker2(_,_,[],Sz) -></span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">   Sz.</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg"></span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg"></span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">1> timer:tc(fun() -> dir:walker("/usr/share") end).</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">{<a href="tel:1538933,28941" dir="ltr" class="gmail_msg" target="_blank">1538933,28941</a>}</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">2> timer:tc(fun() -> dir:walker1("/usr/share") end).</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">{<a href="tel:1492408,447632520" dir="ltr" class="gmail_msg" target="_blank">1492408,447632520</a>}</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">3> timer:tc(fun() -> dir:walker2("/usr/share") end).</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">{<a href="tel:1477578,447632520" dir="ltr" class="gmail_msg" target="_blank">1477578,447632520</a>}</span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg"></span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">Getting close to 1sec. Any other ideas for improvement?</span></div><div class="gmail_msg"><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg"></span><br style="font-family:UICTFontTextStyleBody" class="gmail_msg"><span style="font-family:UICTFontTextStyleBody" class="gmail_msg">/Frank</span></div><div class="gmail_msg"><font face="UICTFontTextStyleBody" class="gmail_msg"><span class="gmail_msg"><br class="gmail_msg"></span></font><div class="gmail_quote gmail_msg"><div class="gmail_msg">Le sam. 10 déc. 2016 à 15:30, Mikael Pettersson <<a href="mailto:mikpelinux@gmail.com" class="gmail_msg" target="_blank">mikpelinux@gmail.com</a>> a écrit :<br class="gmail_msg"></div><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Stanislaw Klekot writes:<br class="gmail_msg"><br class="gmail_msg"> > On Fri, Dec 09, 2016 at 11:15:58PM +0000, Frank Muller wrote:<br class="gmail_msg"><br class="gmail_msg"> > > I would like to improve the speed of my directory walker.<br class="gmail_msg"><br class="gmail_msg"> > ><br class="gmail_msg"><br class="gmail_msg"> > > walk(Dir) -><br class="gmail_msg"><br class="gmail_msg"> > >     {ok, Files} = prim_file:list_dir(Dir),<br class="gmail_msg"><br class="gmail_msg"> > >     walk(Dir, Files).<br class="gmail_msg"><br class="gmail_msg"> ><br class="gmail_msg"><br class="gmail_msg"> > Why prim_file:list_dir() instead of file:list_dir()? The former is<br class="gmail_msg"><br class="gmail_msg"> > undocumented internal function.<br class="gmail_msg"><br class="gmail_msg"><br class="gmail_msg"><br class="gmail_msg">list_dir can be a very time-consuming operation, and in those cases<br class="gmail_msg"><br class="gmail_msg">using file:list_dir would block the single file server for everything<br class="gmail_msg"><br class="gmail_msg">else.  We routinely use prim_file:list_dir to reduce the negative<br class="gmail_msg"><br class="gmail_msg">effects of accessing large directories.<br class="gmail_msg"><br class="gmail_msg"></blockquote></div></div>
_______________________________________________<br class="gmail_msg">
erlang-questions mailing list<br class="gmail_msg">
<a href="mailto:erlang-questions@erlang.org" class="gmail_msg" target="_blank">erlang-questions@erlang.org</a><br class="gmail_msg">
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" class="gmail_msg" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br class="gmail_msg">
</blockquote></div>