chatterbox icon indicating copy to clipboard operation
chatterbox copied to clipboard

How can we know the max of streams allowed on the server

Open posilva opened this issue 8 years ago • 2 comments

Hi,

using the h2_client how can I know the max number of concurrent streams allowed on the server. I can see in the code that the received "SETTINGS" frame saves the other endpoint max concurrent streams in the local connection.

I would like to check the max streams allowed and then when I am sending split the requests in up max streams size request chunks.

Example:

I have to send 1000 requests so, I will check the max streams (100) so I will split the requests in 10 chunks and send and receive the streams until send the 1000 without exceed the max limit on the server (will cause a {ok, {error, 7}} on chatterbox server if we put a limit in the MCS).

Some guidance would be nice

Cheers

posilva avatar Feb 03 '17 00:02 posilva

You could do it like this:

Streams = h2_connection:get_streams(H2Pid),
MCS = (Streams#stream_set.mine)#peer_subset.max_active.

Streams would look something like this:

#stream_set{type = client,
            mine = #peer_subset{max_active = 1000,active_count = 0, ...

I wouldn't do it very frequently, though, because get_streams/1 is a sync event and polling a lot will block the gen_fsm while in progress.

A better way (IMHO) to do it would be to add code to chatterbox to send an event when receiving a frame from the server, and pull the MCS out of that. Or wait until you get the {error, 7} return and stop sending.

Honestly, I'm not sure what is a good way of achieving efficient batching in APNS with chatterbox.

efine avatar Apr 17 '17 20:04 efine

I didn't notice there was a specific accessor you can use to get MCS. This code avoids needing to know the internals:

StreamSet = h2_connection:get_streams(H2Pid),
MCS = h2_stream_set:my_max_active(StreamSet).

EDIT: Duh, I added this accessor to my fork. Sorry. I will offer it as a PR.

efine avatar Apr 18 '17 19:04 efine