users@grizzly.java.net

Re: comet throttling

From: Jeanfrancois Arcand <Jeanfrancois.Arcand_at_Sun.COM>
Date: Mon, 07 Jul 2008 10:32:22 -0400

Salut,

Cam Bazz wrote:
> Hello,
>
> Now my comet application has matured a bit, I would like to add
> functions of throttling. So far, I used an EJB Timer bean to notify the
> comet context, pushing data to every client at the same time.
>
> I successfully used context.getCometHandlers().size() to get the number
> of active users at a given time. (although, it does not work properly in
> IE, but it is probably unrelated - IE will get comet response
> immediately when you issue a get request to the servlet, it wont wait
> until notification is sent)

I think you can workaround that issue by sending "junk" comments at the
beginning of the suspend operation (when you call addCometHandler())


>
> I was thinking one could get an iterator over getCometHandlers, wait a
> while and notify each client individually in a round robin fashion.
> However, this has a drawback, as the number of users increase, the
> notification interval also increases.
>
> Then I found at Jean's blog about throttling:
> http://weblogs.java.net/blog/jfarcand/archive/2007/03/new_adventures_1.html


Exactly.


>
> I understand you implement NotificationHandler in your comet handler
> which gives you the following methods:
>
> public boolean isBlockingNotification();
> /**
> * Set to true if the invoker of notify() should block when
> * notifying Comet Handlers.
> */
> public void setBlockingNotification(boolean blockingNotification);
> /**
> * Notify all CometHandler.
> * @param cometEvent the CometEvent used to notify CometHandler
> * @param iteratorHandlers An iterator over a list of CometHandler
> */
> public void notify(CometEvent cometEvent,Iterator<CometHandler>
> iteratorHandlers)
> throws IOException;
> /**
> * Notify a single CometHandler
> * @param cometEvent the CometEvent used to notify CometHandler
> * @param iteratorHandlers An iterator over a list of CometHandler
> */
> public void notify(CometEvent cometEvent,CometHandler cometHandler)
>
>
> it is almost what I want, but I could not come up with a logic to use
> the code. Are there any examples about this?

Take a look at:

https://grizzly.dev.java.net/nonav/xref/com/sun/grizzly/comet/DefaultNotificationHandler.html


  how can we implement a
> logic that smoothly notifies all the clients in a round robin fashion?

You might want to use a thread pool and get a thread from pool when you
do a notification. With this approach, you also make sure you don't
block on a client that isn't reading fast enough. You waste a thread,
but at least other clients get the response in a "real-time" way.

A+

-- Jeanfrancois





>
> Best Regards,
> -C.B.