[Proto-Scripty] Re: Many Ajax requests, after bih sql query there are no responses

2009-10-10 Thread T.J. Crowder

Hi,

I really wouldn't recommend queuing up 250 Ajax calls like that.  Most
browsers (and most servers, for that matter) will only allow two
connections between the same two endpoints, and then queue the rest,
and it sounds like there might be some bugginess in the queuing (which
doesn't surprise me).  Instead, I'd make the completion of one request
kick off the next.  Semi-pseudocode:

function ajaxTableFill(list, index) {
var url, parameters;

// Make sure call is valid (also ends the loop)
if (index = list.length) {
return;
}

// ...determine URL and parameters...

// Start this request
new Ajax.Request(url, {
parameters: parameters,
onSuccess: function(response) {
// ...handle success...
},
onFailure: function(response) {
// ...handle failure...
},
onComplete: function() {
// Fire off the next request
ajaxTableFill(list, index + 1);
}
});
}

Then kick it off like this:

ajaxTableFill(list, 0);

That would only have one request outstanding at any given time, which
will frequently leave a second channel open for anything else you
might be doing (although you can't take that as a guarantee, you might
have only one channel available).

Of course, if you could collect more than one row's worth of
information on each call, that would also be a really good idea; what
with setup, processing, and teardown, if you figure each request takes
at least a second, 250 requests is more than four minutes!  If you
could grab 50 rows on each (or even all 250 on one call) or something
like that...  But I assume you have some reason for having it broken
into 250 parts.

HTH,
--
T.J. Crowder
Independent Software Consultant
tj / crowder software / com
www.crowdersoftware.com


On Oct 9, 6:59 pm, Dusko Sobic dso...@gmail.com wrote:
 Hi All!

 In brief - I have a table with 250 rows of data and I am trying to
 fill in 2 columns with ajax calls.
 --
 var sel_list_queue = new Array(# this is an array with more than 200
 IDs#);

 if(sel_list_queue.length0) {

     var url = 'ajax/getData.php';
     var fromd = '2009-10-10';
     var tod = '2009-10-11';

     for (var i = 0;isel_list_queue.length;i++)
     {

         if(sel_list_queue[i]!=''){

             var spanname = loader_req_ + sel_list_queue[i];
             var divname = req_ + sel_list_queue[i];
             aja(url, spanname, divname, sel_list_queue[i], 0, fromd,
 tod);

             var spanname = loader_tot_ + sel_list_queue[i];
             var divname = tot_ + sel_list_queue[i];
             aja(url, spanname, divname, sel_list_queue[i], 1, fromd,
 tod);
         }

     }

 }

 function aja(url, spanname, divname, l_id, to, fromd, tod){

     new Ajax.Request('myajax/create_curl_package.php', {
           method: 'post',
           parameters: {
             listid:l_id,
             total:to,
             fromd:fromd,
             tod:tod
           },
           onLoading: function(){Element.show(spanname);},
           onSuccess: function(t) {
               Element.hide(spanname);
               $(divname).update(t.responseText);
           }
         });

 }

 

 getData.php do SELECT COUNT(`id`)...

 Problem: When I start this script I see Loading... in every field in
 mentioned 2 columns, and results start showing. At one moment, when
 getData.php do COUNT() on tabel with 18 000 000 rows everything stops.
 Mysql have no processes in list, about 100 Loading... messages are
 still on the page.

 What could be bottleneck in your opinion. Please help.

 php script do not return any error, i have not found anything in
 Apache log

 Thank you in advanced!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Many Ajax requests, after bih sql query there are no responses

2009-10-10 Thread Alex McAuley

if you need to flush and show te user thngs are loading look at ob_flush() 
in php


Alex Mcauley
http://www.thevacancymarket.com
- Original Message - 
From: T.J. Crowder t...@crowdersoftware.com
To: Prototype  script.aculo.us prototype-scriptaculous@googlegroups.com
Sent: Saturday, October 10, 2009 1:50 PM
Subject: [Proto-Scripty] Re: Many Ajax requests, after bih sql query there 
are no responses



Hi,

I really wouldn't recommend queuing up 250 Ajax calls like that.  Most
browsers (and most servers, for that matter) will only allow two
connections between the same two endpoints, and then queue the rest,
and it sounds like there might be some bugginess in the queuing (which
doesn't surprise me).  Instead, I'd make the completion of one request
kick off the next.  Semi-pseudocode:

function ajaxTableFill(list, index) {
var url, parameters;

// Make sure call is valid (also ends the loop)
if (index = list.length) {
return;
}

// ...determine URL and parameters...

// Start this request
new Ajax.Request(url, {
parameters: parameters,
onSuccess: function(response) {
// ...handle success...
},
onFailure: function(response) {
// ...handle failure...
},
onComplete: function() {
// Fire off the next request
ajaxTableFill(list, index + 1);
}
});
}

Then kick it off like this:

ajaxTableFill(list, 0);

That would only have one request outstanding at any given time, which
will frequently leave a second channel open for anything else you
might be doing (although you can't take that as a guarantee, you might
have only one channel available).

Of course, if you could collect more than one row's worth of
information on each call, that would also be a really good idea; what
with setup, processing, and teardown, if you figure each request takes
at least a second, 250 requests is more than four minutes!  If you
could grab 50 rows on each (or even all 250 on one call) or something
like that...  But I assume you have some reason for having it broken
into 250 parts.

HTH,
--
T.J. Crowder
Independent Software Consultant
tj / crowder software / com
www.crowdersoftware.com


On Oct 9, 6:59 pm, Dusko Sobic dso...@gmail.com wrote:
 Hi All!

 In brief - I have a table with 250 rows of data and I am trying to
 fill in 2 columns with ajax calls.
 --
 var sel_list_queue = new Array(# this is an array with more than 200
 IDs#);

 if(sel_list_queue.length0) {

 var url = 'ajax/getData.php';
 var fromd = '2009-10-10';
 var tod = '2009-10-11';

 for (var i = 0;isel_list_queue.length;i++)
 {

 if(sel_list_queue[i]!=''){

 var spanname = loader_req_ + sel_list_queue[i];
 var divname = req_ + sel_list_queue[i];
 aja(url, spanname, divname, sel_list_queue[i], 0, fromd,
 tod);

 var spanname = loader_tot_ + sel_list_queue[i];
 var divname = tot_ + sel_list_queue[i];
 aja(url, spanname, divname, sel_list_queue[i], 1, fromd,
 tod);
 }

 }

 }

 function aja(url, spanname, divname, l_id, to, fromd, tod){

 new Ajax.Request('myajax/create_curl_package.php', {
 method: 'post',
 parameters: {
 listid:l_id,
 total:to,
 fromd:fromd,
 tod:tod
 },
 onLoading: function(){Element.show(spanname);},
 onSuccess: function(t) {
 Element.hide(spanname);
 $(divname).update(t.responseText);
 }
 });

 }

 

 getData.php do SELECT COUNT(`id`)...

 Problem: When I start this script I see Loading... in every field in
 mentioned 2 columns, and results start showing. At one moment, when
 getData.php do COUNT() on tabel with 18 000 000 rows everything stops.
 Mysql have no processes in list, about 100 Loading... messages are
 still on the page.

 What could be bottleneck in your opinion. Please help.

 php script do not return any error, i have not found anything in
 Apache log

 Thank you in advanced!



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---