Poor performance of abspath

I’m running some stress tests on Genie apps and literally, the first thing that broke the app was a repeated call to abspath. I’m not sure if this can be improved, but if not, maybe the docs can point to the fact that it opens files. In my case, I just refactored the code to remove the call to abspath altogether.

2019-02-16 00:23:41:CRITICAL:Main: 
Base.IOError("getcwd: too many open files (EMFILE)", -24), 
Any[(pwd() at sys.dylib:?, 1), 
(abspath at path.jl:325 [inlined], 1), 
(#file_path#40(::Bool, ::Function, ::String) at Router.jl:1065, 1), 
(file_path at Router.jl:1065 [inlined], 1), 
(is_static_file at Router.jl:952 [inlined], 1), 
(route_request(::Request, ::Response, ::IPv4) at Router.jl:89, 1), 

... etc

(handle_request(::Request, ::Response, ::IPv4) at AppServer.jl:96, 1), 
(handle_request(::Request, ::Response) at AppServer.jl:95, 1), 
(#14 at macros.jl:108 [inlined], 1), 
(run_work_thunk(::##14#17{Request,Response}, ::Bool) at process_messages.jl:56, 1), (#remotecall_fetch#148(::Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::Function, ::LocalProcess) at remotecall.jl:364, 1), (remotecall_fetch(::Function, ::LocalProcess) at remotecall.jl:364, 1), (#remotecall_fetch#152(::Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::Function, ::Int64) at remotecall.jl:406, 1), (remotecall_fetch(::Function, ::Int64) at remotecall.jl:406, 1), (setup_http_handler(::Request, ::Response) at AppServer.jl:60, 1), (setup_http_handler at AppServer.jl:59 [inlined], 1), (#6 at AppServer.jl:40 [inlined], 1), (handle at Handlers.jl:248 [inlined], 1), (handle(::RequestHandlerFunction{##6#12}, ::Stream{Request,Transaction{TCPSocket}}) at Handlers.jl:271, 1), (#4 at Handlers.jl:339 [inlined], 1), (macro expansion at Servers.jl:352 [inlined], 1), ((::##13#14{##4#5{RequestHandlerFunction{##6#12}},Transaction{TCPSocket},Stream{Request,Transaction{TCPSocket}}})() at task.jl:259, 1)]))

Looking at the code I would suspect calling pwd is the culprit, since isabspath is just checking that the path starts with / on non-windows machines.

Yes, still, it’s part of Julia’s internals, within abspath call stack. Maybe I should report this as an issue for Julia…

You can also just increase the ulimit for open files in Linux. By default it’s not a super huge/unlimited number.

bash on gentoo reports an “open files” limit of 1024, which could definitely be easily hit by a server application. You’ll have to increase that limit as root either in /etc/security/limits.conf, or do it as root before running your application:

  1. As root, ulimit -n 2048 to set the limit to 2048 open files (pick a decently large number, but be careful or runaway code will nuke your server)
  2. sudo -u myserveruser ./myjuliaserver

This shouldn’t be leaving any file handles open so this may be a bug. If you could please open an issue, it would be much appreciated.

Thanks @jpsamaroo - I’m on a mac, but that’s good to know.

@StefanKarpinski Issue opened: https://github.com/JuliaLang/julia/issues/31126


You may be able to do the same thing as a temporary workaround, assuming bash or another shell with the appropriate ulimit flags is installed (bash is almost definitely installed). These limits originally come from older Unices that Linux and OSX are based on.