Hi,
On Mon, Sep 2, 2019 at 3:30 PM Ram C <
time...@gmail.com> wrote:
>
> Hi Simone,
>
> I get a message with around 350 event messages merged in a single packet.
You have not explained what your application is about, but I challenge
any human to look at 350 different things in a UI in less than 350
seconds, which is 6 minutes.
The fact that your server side system produces 350 events in a short
period of time does not mean you have to relay all of them.
For example, if these events are stock price changes, you only need to
deliver the final price, say once every second.
> Then cometd.js calls the subscribe call back for each event message, in the callback I call setTimeout(handleEvent, 0). I expect the setTimeout adds task to the queue and returns immediately then subscribe callback returns.
Yes, so now you have 350 events in the JavaScript engine queue.
After all of those, CometD queues the /meta/connect message, so it is
being delayed by your application to process the 350 events.
JavaScript is single threaded and CometD cannot send back a
/meta/connect before all messages are processed (otherwise the client
must perform infinite buffering).
> Is there a way to limit the number of messages sent to the client?
Yes, you don't send them in the first place.
This is entirely application dependent - you have to implement the
logic that decides whether a message should or should not be sent.
You may do this less efficiently by using a
ServerSession.DeQueueListener, where you navigate the queue of
messages and discard those that should not be sent.
> If I set maxQueue=<small number> will that avoid merging all messages in the Queue<ServerMessage>?
No, a small maxQueue will just drop messages without any logic.
> Increasing the maxInterval helps here?
I don't think so.
I think you have a fundamental flaw in your application if you need to
deliver 350 messages at once.