the code is called from test_controller. is there any way i could call
the url?
Please realise that Ruby and Rails are not the same thing. This is a
Ruby mailing list - there are separate forums for Rails. Rails is an
application which just happens to be written *in* Ruby.
Your problem is most likely because the Rails development server is
single-threaded by default. That is, you can't process a second request
while you're in the middle of processing the first one. You *can* turn
on multithreading; please ask on the Rails forum how to do it.
Not using Webrick -- that's a single-threaded server, so it can't
respond to your request until it finishes what it's doing -- sending
your request. Which obviously doesn't work too well.
If you were running something multi-threaded, e.g. multiple unicorns,
Passenger, etc. it would be fine, if architecturally sketchy (IMO).
HTH,
···
On Fri, Jul 22, 2011 at 11:59 AM, Smp Mp <sharnelp@gmail.com> wrote:
When I call call the below code I get a timeout.
http_object = Net::HTTP.new("localhost", "3000")
hresp, data =
http_object.get("/documents/wdocs/generatedata?"+query_string ,"", nil)
But when application is running on port 3000 and a copy of the same
application is running on a different port(3001) , then it works fine.
http_object = Net::HTTP.new("localhost", "3001")
hresp, data =
http_object.get("/documents/wdocs/generatedata?"+query_string ,"", nil)
the code is called from test_controller. is there any way i could call
the url?
WEBrick is not a single-threaded server. It can be configured as a single-threaded server but it is not by default:
require 'webrick'
require 'net/http'
s = WEBrick::HTTPServer.new :Port => 8000
count = 0
s.mount_proc '/count' do |req, res|
count += 1
res.body = count.to_s
end
s.mount_proc '/' do |req, res|
Net::HTTP.start 'localhost', 8000 do |http|
res.body = http.get('/count').body
end
end
trap 'INT' do s.shutdown end
trap 'TERM' do s.shutdown end
s.start
···
On Jul 22, 2011, at 2:46 PM, Hassan Schroeder wrote:
Not using Webrick -- that's a single-threaded server, so it can't
respond to your request until it finishes what it's doing -- sending
your request. Which obviously doesn't work too well.
But certainly the default Rails configuration *appears* to be single-
threaded. If not, why does that simple test case fail when the same
thing works with e.g. a couple of Unicorns?
···
On Fri, Jul 22, 2011 at 3:48 PM, Eric Hodel <drbrain@segment7.net> wrote:
WEBrick is not a single-threaded server. It can be configured as a single-threaded server but it is not by default:
But certainly the default Rails configuration *appears* to be single-
threaded.
It is - not because of an inherent limitation of webrick, but because
Rails itself has a global dispatcher lock. This dates from the days when
Rails internals were not thread-safe. They are now, but because your
application may not be thread safe, the global lock remains unless you
give a configuration command to turn it off. Google "rails config
threadsafe"
Normally it doesn't matter in production, because you're running
multiple server processes (e.g. mongrels, passenger workers etc) behind
some sort of proxy, and you only want each one to be handling one
request at a time.
Ah, right, I'd forgotten all about that. Thanks for the correction!
···
On Fri, Jul 22, 2011 at 11:30 PM, Brian Candler <b.candler@pobox.com> wrote:
It is - not because of an inherent limitation of webrick, but because
Rails itself has a global dispatcher lock. This dates from the days when
Rails internals were not thread-safe.