# Poor performance of abspath

**URL:** <https://discourse.julialang.org/t/poor-performance-of-abspath/20853>\
**Category:** Performance\
**Created:** [February 16, 2019, 9:52am UTC](https://discourse.julialang.org/t/poor-performance-of-abspath/20853 "2019-02-16T09:52:57Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![essenciary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/essenciary/32/210469_2.png) [@essenciary](https://discourse.julialang.org/u/essenciary)\
**Post date:** [February 16, 2019, 9:52am UTC](https://discourse.julialang.org/t/poor-performance-of-abspath/20853/1 "2019-02-16T09:52:57Z")

</div>

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.

```julia
2019-02-16 00:23:41:CRITICAL:Main: 
Distributed.RemoteException(1, 
CapturedException(
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)]))

```

---

<div class="post-metadata">

**Author:** ![jonathanBieler](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@jonathanBieler](https://discourse.julialang.org/u/jonathanBieler)\
**Post date:** [February 16, 2019, 10:00am UTC](https://discourse.julialang.org/t/poor-performance-of-abspath/20853/2 "2019-02-16T10:00:37Z")

</div>

Looking at the [code](https://github.com/JuliaLang/julia/blob/09c31b461501f0fecd3f4da399a77fd33ebc6389/base/path.jl#L325) I would suspect calling [pwd](https://github.com/JuliaLang/julia/blob/111a38feffcc14f929fa3454b0d51693de20f226/base/file.jl#L50) is the culprit, since `isabspath` is just checking that the path starts with `/` on non-windows machines.

---

<div class="post-metadata">

**Author:** ![essenciary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/essenciary/32/210469_2.png) [@essenciary](https://discourse.julialang.org/u/essenciary)\
**Post date:** [February 18, 2019, 7:46am UTC](https://discourse.julialang.org/t/poor-performance-of-abspath/20853/3 "2019-02-18T07:46:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jpsamaroo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jpsamaroo/32/46804_2.png) [@jpsamaroo](https://discourse.julialang.org/u/jpsamaroo)\
**Post date:** [February 18, 2019, 1:05pm UTC](https://discourse.julialang.org/t/poor-performance-of-abspath/20853/4 "2019-02-18T13:05:01Z")

</div>

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`

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [February 18, 2019, 4:19pm UTC](https://discourse.julialang.org/t/poor-performance-of-abspath/20853/5 "2019-02-18T16:19:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![essenciary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/essenciary/32/210469_2.png) [@essenciary](https://discourse.julialang.org/u/essenciary)\
**Post date:** [February 20, 2019, 8:33pm UTC](https://discourse.julialang.org/t/poor-performance-of-abspath/20853/6 "2019-02-20T20:33:04Z")

</div>

> [@essenciary](#):
>
> Distributed.RemoteException(1, CapturedException( 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)]))

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

---

<div class="post-metadata">

**Author:** ![essenciary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/essenciary/32/210469_2.png) [@essenciary](https://discourse.julialang.org/u/essenciary)\
**Post date:** [February 20, 2019, 8:33pm UTC](https://discourse.julialang.org/t/poor-performance-of-abspath/20853/7 "2019-02-20T20:33:30Z")

</div>

@StefanKarpinski Issue opened: [https://github.com/JuliaLang/julia/issues/31126](https://github.com/JuliaLang/julia/issues/31126)

---

<div class="post-metadata">

**Author:** ![jpsamaroo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jpsamaroo/32/46804_2.png) [@jpsamaroo](https://discourse.julialang.org/u/jpsamaroo)\
**Post date:** [February 21, 2019, 3:35pm UTC](https://discourse.julialang.org/t/poor-performance-of-abspath/20853/8 "2019-02-21T15:35:47Z")

</div>

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.
