Apart from improving the performance of requests to the Market (see Issue #41 and PR #42) we also need to make REST API requests only if we don't have a cached version of the AdSlot / AdUnits.
This is quite obvious from the experiments I've made with the Supermarket, showing that most of the time when calling /units-for-slot is actually calling a Market API endpoint and waiting for a response. Although we use TCP / HTTP Keep alive feature (for the hyper used in the proxy client and the API client reqwest) it is not enough to improve the actual response time of the Market endpoint itself.
Improvements:
This is why we need to cache (in memory) the AdSlots & AdUnits for specific time period each, i.e. configurable
[ ] Cache AdSlots (from Market)
[ ] Cache AdUnits (from Market)
[ ] Configurable caching times for AdSlot & AdUnit before invalidating old record and fetching them again.
Performance results:
Examples from the performance review of the /units-for-slot endpoint:
Supermarket is just started, no cache or connections exist
Jan 11 12:49:07.369 INFO Fetched AdSlot, AdSlot: QmSx6jMjm9K1XXgv6AphBqe2wRFn9uu2Y3rn9pTu3DMr8f
Jan 11 12:49:07.369 INFO Fetching AdSlot from Market took 307 ms
Jan 11 12:49:07.651 INFO Fetching ALL AdUnits from the Market took 282 ms
Jan 11 12:49:07.652 INFO Fetching Fallback AdUnit from the Market took 0 ms
Jan 11 12:49:07.652 INFO Fetched 366 AdUnits for AdSlot, AdSlot: QmSx6jMjm9K1XXgv6AphBqe2wRFn9uu2Y3rn9pTu3DMr8f
Jan 11 12:49:07.654 INFO Retrieving campaigns from Cache took 0 ms
Jan 11 12:49:07.655 INFO Preparing and Applying targeting rules took 2 ms
Supermarket after a couple of requests on the same route
I suspect this is thanks to Cloudflare caching, the cache itself doesn't stay for long, after > 30 seconds the request time increases again.
Jan 11 12:54:09.933 INFO Fetching AdSlot from Market took 13 ms
Jan 11 12:54:10.221 INFO Fetching ALL AdUnits from the Market took 288 ms
Jan 11 12:54:10.223 INFO Fetching Fallback AdUnit from the Market took 1 ms
Jan 11 12:54:10.223 INFO Fetched 366 AdUnits for AdSlot, AdSlot: QmSx6jMjm9K1XXgv6AphBqe2wRFn9uu2Y3rn9pTu3DMr8f
Jan 11 12:54:10.224 INFO Retrieving campaigns from Cache took 0 ms
Jan 11 12:54:10.226 INFO Preparing and Applying targeting rules took 0 ms
Performance
Apart from improving the performance of requests to the Market (see Issue #41 and PR #42) we also need to make REST API requests only if we don't have a cached version of the
AdSlot
/AdUnits
. This is quite obvious from the experiments I've made with the Supermarket, showing that most of the time when calling/units-for-slot
is actually calling a Market API endpoint and waiting for a response. Although we use TCP / HTTPKeep alive
feature (for thehyper
used in the proxy client and the API clientreqwest
) it is not enough to improve the actual response time of the Market endpoint itself.Improvements:
This is why we need to cache (in memory) the AdSlots & AdUnits for specific time period each, i.e. configurable
Performance results:
Examples from the performance review of the
/units-for-slot
endpoint:Supermarket is just started, no cache or connections exist
mode: Release Url: http://localhost:3000/units-for-slot/QmSx6jMjm9K1XXgv6AphBqe2wRFn9uu2Y3rn9pTu3DMr8f Fallback unit: None HTTP Cache-Control: no-cache Total response time: 601 ms Market API endpoints time: 589 ms
Supermarket after a couple of requests on the same route
I suspect this is thanks to Cloudflare caching, the cache itself doesn't stay for long, after > 30 seconds the request time increases again.
mode: Release Url: http://localhost:3000/units-for-slot/QmSx6jMjm9K1XXgv6AphBqe2wRFn9uu2Y3rn9pTu3DMr8f Fallback unit: None HTTP Cache-Control: no-cache Total response time: 313 ms Market API endpoints time: 302 ms