Excessive stat calls on /etc/localtime in Rails Application
I just straced my Rails-App and it produces a lot of
stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2309, ...}) = 0
Calls (really a lot!). In 开发者_JAVA百科other contexts I've read that this is because the Timezone is not set. Is there a way to "fix" this?
Best,
Tobias
It's not a ruby issue but rather a C / Linux issue: Setting "TZ" ENV-Var will lead to no more stat calls on etc/localtime. It wont have significant performance impacts though:
# irb
require 'benchmark'
Benchmark.measure { 10_000_000.times { Time.now } }
=> 17.880000 0.540000 18.420000 ( 21.535307)
# same with TZ=CET irb
=> 18.040000 0.550000 18.590000 ( 20.892542)
As @fabio said, you should report this to the Rails forums or mailinglist, because its probably a bug.
However, to set the time zone, in your config/environment.rb
:
Rails::Initializer.run do |config|
config.time_zone = "Central Time (US & Canada)"
end
you can get available time zones with rake time:zones:us
, rake time:zones:local
, or rake time:zones:all
(depending on where you are in the world.)
精彩评论