-
-
Notifications
You must be signed in to change notification settings - Fork 247
-
Target: Reduce the number of requests to the cache service.
How can it be achieved? Implement an additional service over the AtomicServiceInterface, which, after taking the lock, will fix the state of the wallet inside the transaction (until the lock is removed). Instead of accessing the cache, we will access the memory. After the completion of the atomic operation, the fork will be reset, and again they will go to the cache again.
Then for such a code there will be only two or three (depending on the cache service) operations on the cache:
$wallet->balanceInt; // 0. (CQ+1) $atomic->block($wallet, function () use ($wallet) { // create wallet fork & set balance =wallet.balance. (CQ+1) $wallet->withdraw(100); // fork set balance +100 (in memory) $wallet->withdraw(200); // fork set balance +200 (in memory) // save fork data to wallet and remove fork. (CQ+1) }); $wallet->balanceInt; // 300. (CQ+1) // there should be 4 CQ (cache requests) for the entire app
Now (version 9.2) makes about 6 requests for redis.
- Get the balance before the atomic operation (+1);
- When trying to write off, we check the balance (+1);
- At the second write-off, we check the balance (+1);
- Upon completion, we get the balance and update it (+2);
- After completion, we withdraw the wallet balance (+1);
Total: 6 requests in cache.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment
-
Tag: 9.3.0
Beta Was this translation helpful? Give feedback.