FAQ

[Catalyst] long poll AJAX

Jeff robinson
Jun 7, 2011 at 5:08 pm
HI,
I am using Catalyst to display some server side data using AJAX.
Essentially there are 3 main blocks:
1) The users browser, runing javascript and using the XMLHttpRequest
object for the AJAX calls
2) The Catalyst web server
3) A remote data server (RDS). This is another Perl app (POE based)
that has a simple API using JSON.

Some calls on the RDS API basically perform login (to the data source)
and provide status info. One call in particular uses the long poll
AJAX technique to provide minimal delay when the server side data
changes. A particular URL on Catalyst is basically a relay to the
remote data source. It uses IO::Socket to create the necessary TCP
connection.

Here's the problem:

Everything works fine if the data poll is not delayed and the various
AJAX requests are completed in a sequential fashion. However what I'm
looking for is the long poll request to just sit there while other
AJAX requests check status etc. The AJAX requests are made to a single
URL, with an argument that is the request, ie /myserver/ajax/?{JSON
data} From separate tests I know the data source end works fine in
this regard. I'm using firebug's networking screen to check on the
requests from the browser to Catalyst and that looks good. The problem
seems to be a bottleneck in Catalyst, because as soon as the long poll
completes all of the waiting status requests complete instantly as
well. I had imagined that the threading on Catalyst would support the
functionality I'm looking for. Any ideas how to resolve?
Thanks - Jeff
reply

Search Discussions

7 responses

  • Ali Mesdaq at Jun 7, 2011 at 6:59 pm
    Are you sure it's a Catalyst issue? Sounds like it could be a JS issue with your script waiting for responses before moving on to the rest of the ajax calls. Are you using any JS frameworks? A good test could be you create a stub method in catalyst with different wait periods and verify that your JS code is treating them async. I have implemented something that is almost exactly the same (ajax js, catalyst, poe server that uses json interface over tcp) and it worked as expected so I am pretty sure it's not an catalyst issue.

    Thanks,
    ALI MESDAQ
    Sr. Security Researcher

    WEBSENSE, INC.
    ph: +1.858.320.9466
    fax: +1.858.784.4466
    www.websense.com

    Websense TRITON(tm)
    For Essential Information Protection(tm)
    Web Security | Data Security | Email Security



    -----Original Message-----
    From: jeff robinson
    Sent: Tuesday, June 07, 2011 10:08 AM
    To: The elegant MVC web framework
    Subject: [Catalyst] long poll AJAX

    HI,
    I am using Catalyst to display some server side data using AJAX.
    Essentially there are 3 main blocks:
    1) The users browser, runing javascript and using the XMLHttpRequest object for the AJAX calls
    2) The Catalyst web server
    3) A remote data server (RDS). This is another Perl app (POE based) that has a simple API using JSON.

    Some calls on the RDS API basically perform login (to the data source) and provide status info. One call in particular uses the long poll AJAX technique to provide minimal delay when the server side data changes. A particular URL on Catalyst is basically a relay to the remote data source. It uses IO::Socket to create the necessary TCP connection.

    Here's the problem:

    Everything works fine if the data poll is not delayed and the various AJAX requests are completed in a sequential fashion. However what I'm looking for is the long poll request to just sit there while other AJAX requests check status etc. The AJAX requests are made to a single URL, with an argument that is the request, ie /myserver/ajax/?{JSON data} From separate tests I know the data source end works fine in this regard. I'm using firebug's networking screen to check on the requests from the browser to Catalyst and that looks good. The problem seems to be a bottleneck in Catalyst, because as soon as the long poll completes all of the waiting status requests complete instantly as well. I had imagined that the threading on Catalyst would support the functionality I'm looking for. Any ideas how to resolve?
    Thanks - Jeff

    _______________________________________________
    List: Catalyst@lists.scsys.co.uk
    Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
    Dev site: http://dev.catalyst.perl.org/


    To report this as spam, please forward to spam@websense.com. Thank you.


    Protected by Websense Hosted Email Security -- www.websense.com
  • Jeff robinson at Jun 7, 2011 at 7:08 pm
    Ali,
    Pretty sure - I've run all the network tests and even rolled out
    Ethereal to check the packets on the network. I can see the requests
    going from the browser to Cat and being stacked up. BTW this works
    fine as well, as long as you don't having a pending request. Did your
    app use the same long poll approach + have other traffic flowing
    concurrently? If yes then that would be good to know.
    Thanks - J
    On Tue, Jun 7, 2011 at 2:59 PM, Mesdaq, Ali wrote:
    Are you sure it's a Catalyst issue? Sounds like it could be a JS issue with your script waiting for responses before moving on to the rest of the ajax calls. Are you using any JS frameworks? A good test could be you create a stub method in catalyst with different wait periods and verify that your JS code is treating them async. I have implemented something that is almost exactly the same (ajax js, catalyst, poe server that uses json interface over tcp) and it worked as expected so I am pretty sure it's not an catalyst issue.

    Thanks,
    ALI MESDAQ
    Sr. Security Researcher

    WEBSENSE, INC.
    ph: +1.858.320.9466
    fax: +1.858.784.4466
    www.websense.com

    Websense TRITON(tm)
    For Essential Information Protection(tm)
    Web Security | Data Security | Email Security



    -----Original Message-----
    From: jeff robinson
    Sent: Tuesday, June 07, 2011 10:08 AM
    To: The elegant MVC web framework
    Subject: [Catalyst] long poll AJAX

    HI,
    I am using Catalyst to display some server side data using AJAX.
    Essentially there are 3 main blocks:
    1) The users browser, runing javascript and using the XMLHttpRequest object for the AJAX calls
    2) The Catalyst web server
    3) A remote data server (RDS). This is another Perl app (POE based) that has a simple API using JSON.

    Some calls on the RDS API basically perform login (to the data source) and provide status info. One call in particular uses the long poll AJAX technique to provide minimal delay when the server side data changes. A particular URL on Catalyst is basically a relay to the remote data source. It uses IO::Socket to create the necessary TCP connection.

    Here's the problem:

    Everything works fine if the data poll is not delayed and the various AJAX requests are completed in a sequential fashion. However what I'm looking for is the long poll request to just sit there while other AJAX requests check status etc. The AJAX requests are made to a single URL, with an argument that is the request, ie /myserver/ajax/?{JSON data} ?From separate tests I know the data source end works fine in this regard. I'm using firebug's networking screen to check on the requests from the browser to Catalyst and that looks good. The problem seems to be a bottleneck in Catalyst, because as soon as the long poll completes all of the waiting status requests complete instantly as well. I had imagined that the threading on Catalyst would support the functionality I'm looking for. Any ideas how to resolve?
    Thanks - Jeff

    _______________________________________________
    List: Catalyst@lists.scsys.co.uk
    Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
    Dev site: http://dev.catalyst.perl.org/


    ?To report this as spam, please forward to spam@websense.com. ?Thank you.


    ?Protected by Websense Hosted Email Security -- www.websense.com

    _______________________________________________
    List: Catalyst@lists.scsys.co.uk
    Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
    Dev site: http://dev.catalyst.perl.org/
  • Larry Leszczynski at Jun 7, 2011 at 8:23 pm
    Hi Jeff -
    The problem seems to be a bottleneck in Catalyst, because as soon as
    the long poll completes all of the waiting status requests complete
    instantly as well. I had imagined that the threading on Catalyst would
    support the functionality I'm looking for.
    Just a guess... By any chance are you launching Catalyst by running the
    myapp_server.pl script? By default it starts up in single-threaded
    mode. You would need to add the "--fork" option to to make it fork a
    new process for each request.


    HTH,
    Larry
  • Jeff robinson at Jun 7, 2011 at 8:40 pm
    Larry,
    You're a genius! That was it.
    Thanks so much - J
    On Tue, Jun 7, 2011 at 4:23 PM, Larry Leszczynski wrote:
    Hi Jeff -
    The problem seems to be a bottleneck in Catalyst, because as soon as
    the long poll completes all of the waiting status requests complete
    instantly as well. I had imagined that the threading on Catalyst would
    support the functionality I'm looking for.
    Just a guess... ?By any chance are you launching Catalyst by running the
    myapp_server.pl script? ?By default it starts up in single-threaded
    mode. ?You would need to add the "--fork" option to to make it fork a
    new process for each request.


    HTH,
    Larry

    _______________________________________________
    List: Catalyst@lists.scsys.co.uk
    Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
    Dev site: http://dev.catalyst.perl.org/
  • Ali Mesdaq at Jun 7, 2011 at 10:56 pm
    Aha! My configuration was on Apache so that's why I wasn't seeing the same behavior. Good to know the --fork option I always assumed it was forking.

    Thanks,
    ALI MESDAQ
    Sr. Security Researcher

    WEBSENSE, INC.
    ph: +1.858.320.9466
    fax: +1.858.784.4466
    www.websense.com

    Websense TRITONT
    For Essential Information ProtectionT
    Web Security | Data Security | Email Security



    -----Original Message-----
    From: jeff robinson
    Sent: Tuesday, June 07, 2011 1:40 PM
    To: The elegant MVC web framework
    Subject: Re: [Catalyst] long poll AJAX

    Larry,
    You're a genius! That was it.
    Thanks so much - J
    On Tue, Jun 7, 2011 at 4:23 PM, Larry Leszczynski wrote:
    Hi Jeff -
    The problem seems to be a bottleneck in Catalyst, because as soon as
    the long poll completes all of the waiting status requests complete
    instantly as well. I had imagined that the threading on Catalyst
    would support the functionality I'm looking for.
    Just a guess... ?By any chance are you launching Catalyst by running
    the myapp_server.pl script? ?By default it starts up in
    single-threaded mode. ?You would need to add the "--fork" option to to
    make it fork a new process for each request.


    HTH,
    Larry

    _______________________________________________
    List: Catalyst@lists.scsys.co.uk
    Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
    Searchable archive:
    http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
    Dev site: http://dev.catalyst.perl.org/
    _______________________________________________
    List: Catalyst@lists.scsys.co.uk
    Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
    Dev site: http://dev.catalyst.perl.org/


    To report this as spam, please forward to spam@websense.com. Thank you.


    Protected by Websense Hosted Email Security -- www.websense.com
  • John Karr at Jun 10, 2011 at 12:33 am
    I've been dabbling with catalyst for a while and working with Model::DBI. There are a few issues that I haven't figured out to my satisfaction.

    loading the dbi connection strings from myapp.conf

    extending the dbi model with DBIx::Simple. My current method is to create a new dbixsimple object from $self->dbh in every subroutine, I would like to get to a point where this is set up in setup of each dbi model and accessible in a manner like either: my $db = $self->db or $self->do_some_dbixsimple_method( @arguments ).

    I'd also be happy to hear some views on:
    pointers on good coding for dbi models -- the balance between reusability and not ending up with a method in your model for every possible query.

    =====

    The discussion I am attempting to start is about DBI models and not the merits of ORM vs DBI, but about doing DBI models well.
  • Charlie Garrison at Jun 10, 2011 at 1:03 am
    Good morning,
    On 10/06/11 at 12:33 AM -0000, John Karr wrote:

    The discussion I am attempting to start is about DBI models and
    not the merits of ORM vs DBI, but about doing DBI models well.
    What does this have to do with "long poll AJAX"?

    Why are you not using DBIx::Class? I don't know DBIx::Simple but
    maybe all you're wanting is to wrap that with a Catalyst model
    in which case look at Catalyst-Model-Adaptor.

    <http://search.cpan.org/dist/Catalyst-Model-Adaptor/>

    I really can't see how this has any bearing on "long poll AJAX"
    so start a new thread if you want to continue discussing this.


    Charlie

    --
    ? Charlie Garrison ? <garrison@zeta.org.au>

    O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
    ? http://www.ietf.org/rfc/rfc1855.txt

Related Discussions