Throttling websocket requests in a factory

199 views
Skip to first unread message

Nolan Dubeau

unread,
Aug 19, 2013, 4:39:05 PM8/19/13
to ang...@googlegroups.com
Hi folks,

I came across this article by Brian Ford which talks about throttling Socket.io requests to help with digests in a large app - http://briantford.com/blog/huuuuuge-angular-apps.html

I recently built a Factory to support PubNub.com and am having difficulties implementing the throttle.  Here is a working Plunk of the service in action - http://plnkr.co/edit/0w6dWQ4lcqTtdxbOa1EL?p=preview

I'm hoping that someone on the list can help me get the throttle to work.  I think the main issue i'm having is understanding how Brian's example does it with regards to Socket.io's syntax, and how that can apply to the way PubNub handles message callbacks.

Thanks!

Nolan

Nolan Dubeau

unread,
Aug 19, 2013, 4:41:27 PM8/19/13
to ang...@googlegroups.com
I forgot to add the link for the PubNub dev console - http://www.pubnub.com/console

Enter 'pubnubthrottletest' for the channel name, 'demo' for the publish key and 'demo' for the subscribe key.

thanks.

Nolan

Sander Elias

unread,
Aug 20, 2013, 1:42:04 AM8/20/13
to ang...@googlegroups.com
Hi Nolan,

What are you trying to achieve? Do you need all the messages you get from the server, or not? Are they vital to your system? I would set up a que, and then use a timeout to evaluate the queue every x milliseconds. wehn evaluating your que, you can handle or drop whatever strikes your fancy!

Regards
Sander Elias

Stephen Blum

unread,
Aug 20, 2013, 10:33:55 PM8/20/13
to ang...@googlegroups.com
Nolan,

Hi!  You have a good question here but I wanted to confirm if you are considering throttling on the Send or Receive side?

Stephen Blum

unread,
Aug 22, 2013, 1:07:37 AM8/22/13
to ang...@googlegroups.com

Nolan Dubeau

unread,
Aug 22, 2013, 1:48:49 AM8/22/13
to ang...@googlegroups.com
Hi Stephen,

Thanks for taking a stab at this.  Maybe my terminology was off but for clarification I do not want to drop any messages. Rather I want to queue them and control the rate at which Angular digest cycle processes them.  In many cases when a new message arrives you could push the message into the messages array and immediately call $scope.$apply() to force a view update, however if the socket was flooded worth messages you would not want to force the update every time but rather queue them process in batches.  It is important (in my case) that all messages get processed.  I hope this makes sense.  

Thanks!

Nolan
--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.

Stephen Blum

unread,
Aug 23, 2013, 1:37:43 AM8/23/13
to ang...@googlegroups.com
I updated the function on Stackoverflow and Plunker.  Let me know if that works!  - http://plnkr.co/edit/Kv698u?p=preview


On Wednesday, August 21, 2013 10:48:49 PM UTC-7, Nolan Dubeau wrote:
Hi Stephen,

Thanks for taking a stab at this.  Maybe my terminology was off but for clarification I do not want to drop any messages. Rather I want to queue them and control the rate at which Angular digest cycle processes them.  In many cases when a new message arrives you could push the message into the messages array and immediately call $scope.$apply() to force a view update, however if the socket was flooded worth messages you would not want to force the update every time but rather queue them process in batches.  It is important (in my case) that all messages get processed.  I hope this makes sense.  

Thanks!

Nolan

On Thursday, August 22, 2013, Stephen Blum wrote:
Solution posted on Stackoverflow - http://stackoverflow.com/questions/18364918/throttling-pubnub-requests-in-angluarjs/18370670#18370670

On Tuesday, August 20, 2013 7:33:55 PM UTC-7, Stephen Blum wrote:
Nolan,

Hi!  You have a good question here but I wanted to confirm if you are considering throttling on the Send or Receive side?

On Monday, August 19, 2013 10:42:04 PM UTC-7, Sander Elias wrote:
Hi Nolan,

What are you trying to achieve? Do you need all the messages you get from the server, or not? Are they vital to your system? I would set up a que, and then use a timeout to evaluate the queue every x milliseconds. wehn evaluating your que, you can handle or drop whatever strikes your fancy!

Regards
Sander Elias

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+unsubscribe@googlegroups.com.

Nolan Dubeau

unread,
Aug 23, 2013, 8:17:10 AM8/23/13
to ang...@googlegroups.com
Hey Stephen, this is great thanks. Fantastic article which definitely highlights some useful approaches.  I am going to implement today and will provide feedback.  

Cheers!
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.

Stephen Blum

unread,
Aug 23, 2013, 7:21:52 PM8/23/13
to ang...@googlegroups.com
Hi Nolan,

Glad we were able to help.  Let me know if all looks good and make sure to click the "accept answer" on Stack Overflow - http://stackoverflow.com/questions/18364918/throttling-pubnub-requests-in-angluarjs/18370670#18370670
Reply all
Reply to author
Forward
0 new messages