Rich Collins successfully answered Don Miguel de los Platanos's question:

Can I use Ajax to request a controller/script multiple times and simulate multiple threads?

People succeed in answering Don Miguel de los Platanos's questions 42% of the time (8 successes in 19 attempts).

Answers by: Rich Collins

Rich Collins's Answer:

Chat Conversation 803 days ago

hey Miguel Rich Collins at 1:48 PM on Friday June 9th, 2006
Each fastcgi process can handle one request at a time Rich Collins at 1:48 PM on Friday June 9th, 2006
however it will queue requests Rich Collins at 1:49 PM on Friday June 9th, 2006
so the browser can be making multiple XHR (Ajax) requests at the same time Rich Collins at 1:49 PM on Friday June 9th, 2006
and you can get by with only one process Rich Collins at 1:49 PM on Friday June 9th, 2006
well my aim is to have my application hit an acction on a controller. it will pass an id and a string. It will then go and seek out a url associated with the id and search for the string within the contents of the url. I want it to update the status on the calling page. Don Miguel de los Platanos at 1:53 PM on Friday June 9th, 2006
hey Rich Collins at 1:53 PM on Friday June 9th, 2006
I dont want the user to have to wait for each url to be processed sequentially. Don Miguel de los Platanos at 1:54 PM on Friday June 9th, 2006
Ah Rich Collins at 1:54 PM on Friday June 9th, 2006
so the user will enter a bunch of urls Rich Collins at 1:54 PM on Friday June 9th, 2006
I want to know if I can do all the request simultanously Don Miguel de los Platanos at 1:54 PM on Friday June 9th, 2006
and submit Rich Collins at 1:54 PM on Friday June 9th, 2006
the urls well be already preselected for them. the user simply enters a string Don Miguel de los Platanos at 1:55 PM on Friday June 9th, 2006
is that how it will work? Rich Collins at 1:55 PM on Friday June 9th, 2006
ah I see Rich Collins at 1:55 PM on Friday June 9th, 2006
and it will search for that string among a variety of sites. Don Miguel de los Platanos at 1:55 PM on Friday June 9th, 2006
so the user enters a string Rich Collins at 1:55 PM on Friday June 9th, 2006
ok Rich Collins at 1:55 PM on Friday June 9th, 2006
and when you hit submit Rich Collins at 1:55 PM on Friday June 9th, 2006
correct Don Miguel de los Platanos at 1:55 PM on Friday June 9th, 2006
the controller action will go and search all of these sites Rich Collins at 1:55 PM on Friday June 9th, 2006
correct Don Miguel de los Platanos at 1:55 PM on Friday June 9th, 2006
in the mean time you need to update with status Rich Collins at 1:55 PM on Friday June 9th, 2006
ok you can do this Rich Collins at 1:55 PM on Friday June 9th, 2006
have the action that is scraping update the database Rich Collins at 1:56 PM on Friday June 9th, 2006
with information about each scrape Rich Collins at 1:56 PM on Friday June 9th, 2006
so you could have one row for each scrape Rich Collins at 1:56 PM on Friday June 9th, 2006
these would be tied to another table that would hold the search Rich Collins at 1:56 PM on Friday June 9th, 2006
so you could have 2 tables: Rich Collins at 1:56 PM on Friday June 9th, 2006
searches Rich Collins at 1:56 PM on Friday June 9th, 2006
which would hold the user_id and the search Rich Collins at 1:57 PM on Friday June 9th, 2006
and then you could have scrapes Rich Collins at 1:57 PM on Friday June 9th, 2006
which would hold a search_id and a status field Rich Collins at 1:57 PM on Friday June 9th, 2006
so the first action could create the scrape rows Rich Collins at 1:57 PM on Friday June 9th, 2006
and then update them as it scrapes Rich Collins at 1:58 PM on Friday June 9th, 2006
and then you could have a periodic request: Rich Collins at 1:58 PM on Friday June 9th, 2006
http://api.rubyonrails.com/classes/ActionView/Helpers/PrototypeHelper.html#M000413 Rich Collins at 1:58 PM on Friday June 9th, 2006
that would call a different rails action Rich Collins at 1:58 PM on Friday June 9th, 2006
say update_scrape_info Rich Collins at 1:58 PM on Friday June 9th, 2006
with the search id Rich Collins at 1:58 PM on Friday June 9th, 2006
then it would return javascript (using RJS) Rich Collins at 1:59 PM on Friday June 9th, 2006
that would update the status of the scrapes Rich Collins at 1:59 PM on Friday June 9th, 2006
you may want to consider using a daemon to do the scrapes Rich Collins at 1:59 PM on Friday June 9th, 2006
instead of the action Rich Collins at 1:59 PM on Friday June 9th, 2006
Could I read a response for the action and update a div in a similar matter? Don Miguel de los Platanos at 1:59 PM on Friday June 9th, 2006
the daemon would run separately Rich Collins at 1:59 PM on Friday June 9th, 2006
yes, you don't have to use rjs Rich Collins at 2:00 PM on Friday June 9th, 2006
would the daemon be able to work on demand? Don Miguel de los Platanos at 2:00 PM on Friday June 9th, 2006
you could have the remote_call update the div Rich Collins at 2:00 PM on Friday June 9th, 2006
probably easier Rich Collins at 2:00 PM on Friday June 9th, 2006
the scrape is usually a post or a get to a search page Don Miguel de los Platanos at 2:00 PM on Friday June 9th, 2006
well the daemon would run outside of the web server Rich Collins at 2:00 PM on Friday June 9th, 2006
and would look for new searches Rich Collins at 2:00 PM on Friday June 9th, 2006
we have a regex that determines if it comes back true or not Don Miguel de los Platanos at 2:00 PM on Friday June 9th, 2006
when it found a new search Rich Collins at 2:00 PM on Friday June 9th, 2006
I see Rich Collins at 2:01 PM on Friday June 9th, 2006
well the only problem with doing the scrape from the action Rich Collins at 2:01 PM on Friday June 9th, 2006
is the possibility of a timeout if the scrape takes too long Rich Collins at 2:01 PM on Friday June 9th, 2006
or if the user leaves the page Rich Collins at 2:01 PM on Friday June 9th, 2006
the search will stop Rich Collins at 2:01 PM on Friday June 9th, 2006
if you just have the daemon grab new searches out of the database Rich Collins at 2:02 PM on Friday June 9th, 2006
then you won't have to worry abou tit Rich Collins at 2:02 PM on Friday June 9th, 2006
however the daemon is more complicated Rich Collins at 2:02 PM on Friday June 9th, 2006
so you may just want to do it in the action Rich Collins at 2:02 PM on Friday June 9th, 2006
If I use ajax to make multiple calls to that action, if say one times out, it shouldn't affect the other searches as well? Don Miguel de los Platanos at 2:02 PM on Friday June 9th, 2006
and then switch over to the daemon Rich Collins at 2:02 PM on Friday June 9th, 2006
if it becomes a problem Rich Collins at 2:02 PM on Friday June 9th, 2006
that you discover from actual use Rich Collins at 2:02 PM on Friday June 9th, 2006
always better to do it the simplest way possible Rich Collins at 2:03 PM on Friday June 9th, 2006
and then get more complex only after real use has demonstrated the problem Rich Collins at 2:03 PM on Friday June 9th, 2006
ah I need to fix this div Rich Collins at 2:03 PM on Friday June 9th, 2006
it overflows horizontally Rich Collins at 2:03 PM on Friday June 9th, 2006
well this applicaiton will be used by over 200 people a day, with each person performing 50+ searches a day Don Miguel de los Platanos at 2:03 PM on Friday June 9th, 2006
speed and scalability is a huge issue. Don Miguel de los Platanos at 2:04 PM on Friday June 9th, 2006
no each action is independent Rich Collins at 2:04 PM on Friday June 9th, 2006
excellent Don Miguel de los Platanos at 2:04 PM on Friday June 9th, 2006
unless you are getting multiple hits per second Rich Collins at 2:04 PM on Friday June 9th, 2006
it shouldn't be Rich Collins at 2:04 PM on Friday June 9th, 2006
that answers my question, thanks Rich. Don Miguel de los Platanos at 2:04 PM on Friday June 9th, 2006
always worry about scalability after you prove it is a problem Rich Collins at 2:04 PM on Friday June 9th, 2006
through actual measurement Rich Collins at 2:04 PM on Friday June 9th, 2006
ok no problem Miguel - good luck! Rich Collins at 2:05 PM on Friday June 9th, 2006