faye - help with configuration?

92 views
Skip to first unread message

lovely rachel

unread,
Feb 11, 2011, 11:29:34 AM2/11/11
to Faye users, ttes...@solaradata.com
i have a question and may need some help configuring faye correctly.
right now a ruby server manages publishing data to a channel.

on the browser side i have the code down below.
i notice in firebug that faye seems to be continually pinging the
server with the shorthened versio reading something like:

GET faye?message

and in the info message on the bottom of the browser "waiting for ...
(our web site)"

i am surprised to see this as i was thinking that there would just be
a channel continuously open.
is there a configuration set up on the browser side so that what
appears as pinging stops and just a channel is opened?




init: function(bayeux) {
var self = this;
this._bayeux = new Faye.Client('http://' +
window.location.hostname + ':9292/faye');
this._bayeux.subscribe('/receive/account/<%= current_account.id
%>', this.accept, this);
//this._bayeux.subscribe('/receive/user/<%= current_user.id %>',
this.accept, this);
},

/**
* Handler for messages received over subscribed channels. Takes the
* message object sent by the post() method and sends it to
* send_to_msg_handler
*/
accept: function(message) {
var sar = Ext.util.JSON.decode(message);
// alert(sar)
this.send_to_msg_handler(sar)
},



James Coglan

unread,
Feb 11, 2011, 11:47:16 AM2/11/11
to Faye users
On Feb 11, 4:29 pm, lovely rachel <rachig...@gmail.com> wrote:
> on the browser side i have the code down below.
> i notice in firebug that faye seems to be continually pinging the
> server with the shorthened versio reading something like:
>
> GET faye?message
>
> and in the info message on the bottom of the browser "waiting for ...
> (our web site)"
>
> i am surprised to see this as i was thinking that there would just be
> a channel continuously open.

In Firefox (which doesn't have WebSocket), Faye uses XMLHttpRequest or
JSON-P depending on which domain you're connecting to. This
unfortunately means the client must make a series of long-running HTTP
requests for new data, which is what you're seeing.

The frequency of these can be tuned by setting the 'timeout' setting
on the server side, but make sure you increase the timeout on Thin and
any other frontend servers you're using to be larger than your Faye
timeout setting, otherwise the frontend server will close connections
before the Faye backend responds.

lovely rachel

unread,
Feb 11, 2011, 3:01:56 PM2/11/11
to Faye users, ttes...@solaradata.com
ok.
out of curiosity does IE have websockets?
which browser in your opinion do you get best results?

i also have alot of googlemap lookups and i worry that faye on firefox
is slowing down the
mapping functionality.

James Coglan

unread,
Feb 12, 2011, 3:40:41 PM2/12/11
to faye-...@googlegroups.com, ttes...@solaradata.com
On 11 February 2011 20:01, lovely rachel <rach...@gmail.com> wrote:
out of curiosity does IE have websockets?
which browser in your opinion do you get best results?

IE does not have WebSockets, even in version 9 as far as I know. Chrome's the best by far, in that it has WebSocket and is generally speedy. Firefox 4 was pretty good until they took WebSocket out.
 
i also have alot of googlemap lookups and i worry that faye on firefox
is slowing down the
mapping functionality.

This might be possible if Faye is using JSON-P. From your example it looks like your Faye server is on the same domain as your page, so it should be using XHR. You can find out what it's doing using the logger:

Faye.Logging.logLevel = 'debug'
Faye.logger = function(msg) { console.log(msg) }

Look for "connectionType" in the output to see what it's using.

If it is using JSON-P, that's going to hold up any other JSON-P calls your page makes. This is because JSON-P involves injecting new script tags into the page, and Firefox executes scripts in the order they appear in the document, not in the order they finish downloading. This means JSON-P calls can easily queue up behind a long-running Faye request, making other APIs sluggish.

For this reason, I want to see if I can add CORS support to replace JSON-P to fix issues like this. I'd check whether any other APIs you're using also support CORS as this is a better way of making cross-domain API calls.

lovely rachel

unread,
Feb 14, 2011, 12:08:57 PM2/14/11
to Faye users, ttes...@solaradata.com
To me it looks ,ike to connection type is: "connectionType":"callback-
polling"

is this what you would expect?
if not, is there another connection type that should be set?

On Feb 12, 2:40 pm, James Coglan <jcog...@gmail.com> wrote:

James Coglan

unread,
Feb 14, 2011, 12:18:26 PM2/14/11
to faye-...@googlegroups.com, ttes...@solaradata.com
On 14 February 2011 17:08, lovely rachel <rach...@gmail.com> wrote:
To me it looks ,ike to connection type is: "connectionType":"callback-
polling"

is this what you would expect?

Right, that means it's using JSON-P, which is holding your scripts up. Suggested solution: if this is really is a problem you've got a couple of things you could try:

* Reduce the timeout on your Faye server. This means the client will have to make more requests, but they'll finish sooner so other APIs can use JSON-P more frequently.

* (I've not tried this but it might work) Put the Faye client on a page that you embed in your main page using an invisible iframe. This might mean you avoid JSON-P contention (separate document, therefore separate JS runtime), and you can still call back to the main page using window.parent:

    // in iframe document
    client.subscribe('/some/channel', function(message) {
        window.parent.receiveFayeMessage('/some/channel', message);
    });

Now you just need a function in the parent document called receiveFayeMessage() and you're away.

Let me know if any of this works, and keep your eye on this mailing list to find out if I add CORS support.

lovely rachel

unread,
Feb 15, 2011, 7:43:54 PM2/15/11
to Faye users, ttes...@solaradata.com
i am trying the iframe solution and it seems like the googlemaps is
funtioning much better!!
i just implemented it and will have to give it another day to be sure.

thanks for your quick response and suggestions, they were quite
helpful.

On Feb 14, 11:18 am, James Coglan <jcog...@gmail.com> wrote:

James Coglan

unread,
Feb 16, 2011, 5:29:34 AM2/16/11
to faye-...@googlegroups.com
On 16 February 2011 00:43, lovely rachel <rach...@gmail.com> wrote:
i am trying the iframe solution and it seems like the googlemaps is
funtioning much better!!
i just implemented it and will have to give it another day to be sure.

That's great! I've not actually tried doing it myself so might give it a go and write up a blog post.

Also I wonder whether I could automate this so that Faye uses an iframe to make JSON-P calls all the time. Probably not as worthwhile as adding CORS support, since Firefox supports that.

DaveM

unread,
Jul 9, 2011, 7:52:37 PM7/9/11
to faye-...@googlegroups.com
James, I'm wondering why the iframe method wouldn't be the standard way, as presumably it's more likely that one would be using Faye and ajax together, no?

David

James Coglan

unread,
Jul 9, 2011, 8:32:45 PM7/9/11
to faye-...@googlegroups.com
On 10 July 2011 00:52, DaveM <dmo...@gmail.com> wrote:
James, I'm wondering why the iframe method wouldn't be the standard way, as presumably it's more likely that one would be using Faye and ajax together, no?

Since version 0.6, the only browser still using JSON-P is Opera; all the others use WebSocket or CORS. Is there still a problem making JSON-P calls in Opera?
Reply all
Reply to author
Forward
0 new messages