We've noticed a couple couch_proc_manager backups when deploying the latest version. Inspecting code I ended up stumbling over the new config code. Its theoretically quite a bit slower than the old code since its doing OS env checking but its also doing things quite inefficiently beyond that.
https://github.com/apache/couchdb/blob/master/src/couch/src/couch_proc_manager.erl#L375-L383
The three big things to notice here are that we're joining the variable names inside the loop which is a bit wasteful. Given the size of the strings I'm not sure how bad that is though. I'd wager it likely depends on how many environment variables there are to know whether its making a difference. The tokens call with a pattern match also seems like an expensive thing to be doing. However the killer bit is probably that we're looping over os:getenv() every time we create a new process which is likely what's caused the backups.
I'd propose two changes. The first simpler of the two is to just create our expected environment variable and use os:getenv/1.
Something like:
get_env_for_spec(Spec, Target) ->
SpecStr = Spec ++ Target,
os:getenv(SpecStr, undefined).
We're still going to be hitting os:getenv/1 every time we create a new process though so I'd also recommend caching succcessful finds in an ets table or similar. That would allow us to have similar speed to before the patch while still maintaining the OS env config approach.
We've noticed a couple couch_proc_manager backups when deploying the latest version. Inspecting code I ended up stumbling over the new config code. Its theoretically quite a bit slower than the old code since its doing OS env checking but its also doing things quite inefficiently beyond that.
https://github.com/apache/couchdb/blob/master/src/couch/src/couch_proc_manager.erl#L375-L383
The three big things to notice here are that we're joining the variable names inside the loop which is a bit wasteful. Given the size of the strings I'm not sure how bad that is though. I'd wager it likely depends on how many environment variables there are to know whether its making a difference. The tokens call with a pattern match also seems like an expensive thing to be doing. However the killer bit is probably that we're looping over
os:getenv()every time we create a new process which is likely what's caused the backups.I'd propose two changes. The first simpler of the two is to just create our expected environment variable and use
os:getenv/1.Something like:
We're still going to be hitting
os:getenv/1every time we create a new process though so I'd also recommend caching succcessful finds in an ets table or similar. That would allow us to have similar speed to before the patch while still maintaining the OS env config approach.