One thing jumps out immediately that could probably solve your issue. The
first line of store_image reads:
container = @my_fog.directories.get(image_container)
This does an http request and pulls back data/parses (and as we saw can be
quite slow in some cases). In this case, if you can reasonably assume that
this directory already exists, you can skip the http request by doing this:
container = @my_fog.directories.new(:key => image_container)
That will create just a local reference without making any remote calls,
which you can then chain the other commands on to do file creation. Pretty
sure that simple change should pretty much take care of the issues you
mentioned (though there may be further room for improvement). Sorry that
this is non-obvious (I've seen another of other people encounter the same
issue). Definitely welcome any suggestions about how we can make this
behavior clearer in the documentation or elsewhere.
Thanks!
wes
Post by ha--> Pull some XML, parse, read some images
Then each image (original, and a few resized ones) go through a code
@my_fog = Fog::Storage.new(
provider: 'Rackspace',
rackspace_username: rack_username,
rackspace_api_key: rack_api_key
)
def store_image(filename, image_file)
image_container is like '<RACK_ENV>_images<CONTAINER_NUMBER>'
new_object = container.files.create(
:body => open(image_file),
:public => true,
:content_type => 'image/jpeg'
)
new_object.public_url
rescue => e
msg = e.respond_to?(:message) ? e.message : e
raise MyERROR.new("Error storing image: #{msg}", "IMAGE_STORE")
end
Then the process go back to the beginning and keep doing it until all the
XMLs are parsed and all images are stored in Rackspace.
It does seems easy for me to detach this code from the app and see if I
can get a script doing just this so I can optimize.
I'll first switch from using Fog and storing the files locally so I can
then compare with same image sample.
1. Remote storage (Fog+Rackspace): 3 hours for about 3k images
2. Local storage: 15 minutes
3. The code I sent below without using Time.parse(...): I expect to take 2
hours, but I haven't run a full simulation with production data
Thanks a lot for helping!
./Helio
Post by geemus (Wesley Beary)Cool, yeah whatever extra info you can provide would help narrow this down.
Post by haI'm not sure I'll be able to get something runnable but I can list the
steps my process goes through Fog library to remote store files in
Rackspace.
when :time
puts "This is name: #{name}"
class_eval <<-EOS, __FILE__, __LINE__
def #{name}=(new_#{name})
attributes[:#{name}] = if new_#{name}.nil? || new_#{name}
== "" || new_#{name}.is_a?(Time)
new_#{name}
else
# Let's see what happens...
#Time.parse(new_#{name})
new_#{name}
end
end
EOS
The result I get in the ruby-prof is around 30% better, just by
eliminating Time.parse(...).
./Helio
Post by geemus (Wesley Beary)Hmm. I don't think it should just be the time parsing. ha, could you
share the code where the problem is occurring? Also, running with
`ENV['EXCON_DEBUG']="true"` may be enlightening (I'm suspecting there are
more api calls happening than one might think.
Post by Kyle RamesThe more I research this, the more I am convenced this is an issue
with Ruby's time implementation.
According to the home_run gem (which is alternative date
implementation for Ruby), the standard Date library was re-written in C and
received a significant speed boost.
https://github.com/**jeremyevans**/home_run#not-**necessary-in-193<https://github.com/jeremyevans/home_run#not-necessary-in-193>
However, when I execute the following in irb
require 'time'
Time.method(:parse).source_**loc**ation
It says that it is coming from a ruby file.
["/Users/kyle.rames/.rvm/**rubie**s/ruby-1.9.3-p286/lib/**ruby/1.**9.1/time.rb",
263]
Does anyone have an ideas? Are we using the wrong method for this?
Kyle
Post by haThanks Kyle,
Going through the Fog code I got this block that seems to be doing
the parse.
* when :time*
* class_eval <<-EOS, __FILE__, __LINE__*
* def #{name}=(new_#{name})*
* attributes[:#{name}] = if new_#{name}.nil? ||
new_#{name} == "" || new_#{name}.is_a?(Time)*
* new_#{name}*
* else*
* Time.parse(new_#{name})*
* end*
* end*
* EOS*
That is inside lib/fog/core/attributes.rb.
I'm trying to set that directly in my code to move from the false to
the true side of the if!
./Helio
Post by Kyle RamesI am still researching this, but it sounds like Ruby's time parsing
https://github.com/**jordansisse****l/experiments/tree/**master/**
ruby**/time-parsing-is-**slow<https://github.com/jordansissel/experiments/tree/master/ruby/time-parsing-is-slow>
Kyle
Post by haHi guys,
I'm troubleshooting some latency issues in one of our backend
services and I'm getting a strange result.
Not sure if I'm reading the result correctly, so see the pic of the
ruby-prof output.
* ruby-1.9.3-p194 [ x86_64 ]
* fog (1.8.0)
* daemons (1.1.8)
It seems to me that 67% of the time is being spent in
"Directories::get"
67.02% (95.29%) Fog::Storage::Rackspace::**Direc****tories#get [56
calls, 56 total]
And 32% spent to set last_modified attribute and time parsing.
32.26% (64.75%) Fog::Storage::Rackspace::File#******last_modified=
[101185 calls, 101241 total]
Any clue on what is going on?
Thanks,
./Helio
--
You received this message because you are subscribed to the Google
Groups "ruby-fog" group.
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/**grou**ps/opt_out<https://groups.google.com/groups/opt_out>
.
--
You received this message because you are subscribed to the Google
Groups "ruby-fog" group.
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
.
--
You received this message because you are subscribed to the Google Groups "ruby-fog" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "ruby-fog" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-fog+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.