I want to display some Amazon products, loaded via Ajax.
I call the method below with Ajax, but the request takes a couple of seconds.
@items = []
@shows.shuffle.first(5).each do |show|
req = AmazonProduct["us"]
req.configure do |c|
c.key = "###"
c.secret = "###"
c.tag = "###"
end
req << { :operation => 'ItemSearch',
:search_index => params[:product_type],
:response_group => %w{ItemAttributes Images},
:keywords => show.name,
:sort => "" }
resp = req.get
@items << resp.find('Item').shuffle.first
end
I've nothiced that this Action blocks the server. I've tried having the site open in another tab. That tab won't start loading until the first tab with the Ajax call completes.
How can I go about solving this problem?
Setup:
Ubuntu 10.10
Rails 3.1.1
Ruby 1.9.2
Gem: https://github.com/hakanensari/amazon_product
I suspect this blocks because you are doing your testing in development mode, using the default Rails sever, Webrick.
My understanding is that webrick can only process one request at a time (which is why it's not suggested for production use).
A production level Rails sever, like Phusion Passenger, or a cluster of mongrel/thin servers, will get you your concurrency :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With