Responses are unconditionally cached for EXCHANGE_LIFETIME
#586
Labels
enhancement
New feature or request
EXCHANGE_LIFETIME
#586
When processing a response, all responses to
CON
andNON
messages are cached for247
seconds (EXCHANGE_LIFETIME
):go-coap/udp/client/conn.go
Line 721 in 91a04ea
go-coap/udp/client/conn.go
Line 623 in 91a04ea
go-coap/udp/client/conn.go
Line 34 in 91a04ea
This is due to the language in Section 4.5 of RFC 7252.
Each
Conn
maintains its ownresponseMsgCache
:go-coap/udp/client/conn.go
Line 148 in 91a04ea
The cache is checked for expiration whenever the
Conn
expirations are checked:go-coap/udp/client/conn.go
Line 910 in 91a04ea
This allows for a recipient to respond to duplicate requests without processing multiple times. However, it also means that endpoints that send large volumes of data have the potential to grow very large caches. There is no mechanism in
go-coap
today to modify theEXCHANGE_LIFETIME
, and theresponseMsgCache
has unbounded size. This is particularly an issue in the case of blockwise transfers, where a single large object may be transmitted over many messages. With the current implementation, that entire large object could end up in the cache. Furthermore, if multiple connections are all fetching the same large object, many copies of the same object may end up in the cache (i.e. one in eachConn
responseMsgCache
). In the same section of RFC 7252, it allows for relaxation of caching behavior:There are a few different mechanisms that could be introduced (potentially alongside each other) to address this behavior:
Conn
responseMsgCache
size bounded such that it cannot grow unconditionally. Using an LRU strategy could be simple approach to ensuring that responses sent most recently are more likely to be in the cache.EXCHANGE_LIFTETIME
.I would be happy to work on implementation if these features are of interest. Thanks!
The text was updated successfully, but these errors were encountered: