Debian Codegraph @

c/docs/buffering.md

raw
1 ## Buffering {#buffering}
2
3 AMQP and proton have mechanisms to allow an application to control it's use of memory.
4
5 ### Outgoing Data
6
7 The unit of memory control in AMQP is the *session*.
8 `pn_session_outgoing_bytes()` tells you the total bytes buffered for all
9 outgoing deliveries on all sending links belonging to that session.
10
11 Each call to `pn_link_send()` adds to the session's outgoing byte total. Each
12 time proton writes data to the network it reduces the total. To control the
13 memory used by a session, check `pn_session_outgoing_bytes()` before
14 calling `pn_link_send()`. If it is too high, stop sending until the link
15 gets a @ref PN_LINK_FLOW event.
16
17 The AMQP protocol allows peers to exchange session limits so they can predict
18 their buffering requirements for incoming data (
19 `pn_session_set_incoming_capacity()` and
20 `pn_session_set_outgoing_window()`). Proton will not exceed those limits when
21 sending to or receiving from the peer. However proton does *not* limit the
22 amount of data buffered in local memory at the request of the application. It
23 is up to the application to ensure it does not request more memory than it wants
24 proton to use.
25
26 #### Priority
27
28 Data written on different links can be interleaved with data from any other link
29 on the same connection when sending to the peer. Proton does not make any formal
30 guarantee of fairness, and does not enforce any kind of priority when deciding
31 how to order frames for sending. Using separate links and/or sessions for
32 high-priority messages means their frames *can* be sent before already-buffered
33 low-priority frames, but there is no guarantee that they *will*.
34
35 If you need to ensure swift delivery of higher-priority messages on the same
36 connection as lower-priority ones, then you should control the amount of data
37 buffered by proton, and buffer the backlog of low-priority backlog in your own
38 application.
39
40 There is no point in letting proton buffer more than the outgoing session limits
41 since that's all it can transmit without peer confirmation. You may want to
42 buffer less, depending on how you value the trade-off between reducing max
43 latency for high-priority messages (smaller buffer) and increasing max
44 throughput under load (bigger buffer).
45
46 ### Incoming Data
47
48 To Be Done... <!-- TODO aconway 2018-05-03: -->