Loading program that uses gems on network share is incredibly slow

N

nikolai.weibull

Hi!

Loading program that uses gems on network share is incredibly slow.
Ruby’s need, due to Rubygems, to search a long list of directories for
a file to load due to a require can become very tedious on, for
example, an SMB share. Loading about a hundred files and having a
$LOAD_PATH with 20 directories in it equals an insane amount of
filesystem accesses. Taking network latency into consideration and
you’ve got unworkable delays at startup.

I was wondering if anyone has had a similar experience and, if so,
what they did to solve it.

One solution I thought of would be to delay as many of the requires as
possible, only requiring when the functionality is needed and perhaps
using autoload.

Another thought I had was to force Rubygems to look in the gem that
the require is coming from first, perhaps by inspecting
Kernel#caller. This would lead to a lot fewer directories being
searched, but would, it seems, require monkeypatching Rubygems.

Is there any way to treat Rubygems more like jars, so that a .gem
would remain packaged until loaded. This would greatly lessen the
network traffic and filesystem traversal, in my case.

I don’t want to debate the merits of storing files on a network
share. Deploying programs on an SMB share at work instead of on each
user’s computer saves me so much trouble.

Thanks!
 
J

Joel VanderWerf

Loading program that uses gems on network share is incredibly slow.
Ruby’s need, due to Rubygems, to search a long list of directories for
a file to load due to a require can become very tedious on, for
example, an SMB share.

One option is to avoid using rubygems on the client systems. The
crown[1] tool I developed collects gem files (including dependencies) in
a set of lib and bin dirs. Just add those dirs (still on the file share)
to the client-side RUBYLIB and PATH env vars. Whenever you gem update,
you would need to recreate the "crown", as well, but no need to touch
the clients. This is experimental, of course, so YMMV, especially if
there is a gem that does something really non-standard to access its
libs. I've been using it in production, but have tested it only on the
gems I use (web stack with sinatra, thin, sequel).

[1] http://github.com/vjoel/crown
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top