Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

StateServiceInterface #562

rez1dent3 started this conversation in Ideas
Discussion options

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.

  1. Get the balance before the atomic operation (+1);
  2. When trying to write off, we check the balance (+1);
  3. At the second write-off, we check the balance (+1);
  4. Upon completion, we get the balance and update it (+2);
  5. After completion, we withdraw the wallet balance (+1);

Total: 6 requests in cache.

You must be logged in to vote

Replies: 1 comment

Comment options

rez1dent3
Sep 6, 2022
Maintainer Author

Tag: 9.3.0

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
1 participant

AltStyle によって変換されたページ (->オリジナル) /