Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSM dapp, wallet poll RPC nodes rapidly #6870

Closed
3 tasks
dckc opened this issue Jan 27, 2023 · 6 comments
Closed
3 tasks

PSM dapp, wallet poll RPC nodes rapidly #6870

dckc opened this issue Jan 27, 2023 · 6 comments
Assignees
Labels
bug Something isn't working performance Performance related issues UI v1_triaged DO NOT USE vaults_triage DO NOT USE

Comments

@dckc
Copy link
Member

dckc commented Jan 27, 2023

Describe the bug

When using our wallet or PSM dapp, the browser makes a dozen or so requests per second to an RPC server.

@arirubinstein noted a cosmos community operational norm of <= 2 requests / second per client on RPC servers.

To Reproduce

  1. Open the wallet and/or dapp-psm
  2. Connect your keplr wallet
  3. check the browser console and/or network inspector
  4. see many more than 2 requests per second to RPC node as we poll every ~400ms at N vstorage keys etc.

This is from memory. IOU a more direct observation, including log exerpt.

Expected behavior

  • rate limiting to <= 2 requests per second to any 1 RPC server

I gather from @michaelfig that there are plans for @agoric/casting to meanwhile support

#6647 will reduce HTTP requests by half.

Platform Environment

mainnet / prod; any browser / os

IOU one example of all these details

  • what OS are you using? what version of Node.js?
  • is there anything special/unusual about your platform?
  • what version of the Agoric-SDK are you using? (run git describe --tags --always)

Additional context

A community member trying out dapp-psm asked why it was making so many requests so rapidly, noting several requests per second in their browser console. (I thought they opened an issue, so this might be a dup.)

@samsiegart and @turadg and I have noted this in a couple recent PRs (back-links to follow).

Screenshots

IOU log excerpt

@dckc dckc added bug Something isn't working performance Performance related issues UI labels Jan 27, 2023
@dckc
Copy link
Member Author

dckc commented Jan 27, 2023

test-watch-balances.js is WIP (#6807) to read x/bank balances using casting, to get

  • proofs
  • multi-RPC-node fail-over
  • batching

and all those goodies.

cannot push to something in xstream

It currently fails a la...

@@balances {
  value: '\n\fibc/usdc1234\x12\n1476000000',
  blockHeight: 1761,
  currentBlockHeight: 1761
}
retrying CosmJS follower (round-robin endpoints) in 880ms after attempt #0 (TypeError#1)
TypeError#1: Cannot add property 0, object is not extensible

  at Array.push (<anonymous>)
  at packages/casting/src/follower-cosmjs.js:159:33

grr... somebody is monkeying with the stack trace. line 159 is const info = await client.abciInfo();

With the JS debug console, I can see the offending .push(). But it's deep in xstream, inside some cosmjs stream thing. I suppose we hardened something that somebody wasn't expecting to be hardened, but I'm having a hard time seeing what.

@dckc
Copy link
Member Author

dckc commented Apr 26, 2023

interim approach: reduce polling frequency... perhaps something around the block time

@samsiegart
Copy link
Contributor

I'm observing that the default behavior is to jitter about every 2-4 seconds. We could maybe do every 8 seconds for a ~2-3x reduction in cost without much noticeable UX difference. A longer reduction might be poor UX if users see, for example, offers completing but their vault dashboard not updating for a long time.

Screenshot 2023-04-26 at 1 28 07 PM

However, I think the real problem is these queries keep going as long as you have the window open. So, someone who incidentally has several tabs open for hours will rack up a lot of data transfer (I estimate 2 MB transferred per minute per dapp-inter tab). We could try not querying if the app isn't in focus, but users might have it open on the side expecting it to update while they interact with a different window.

It's probably best to just go straight for the websocket/long-polling solution.

@samsiegart
Copy link
Contributor

Actually, looks like document.hidden is smart enough to know whether the window is out of focus and hidden or just out of focus: https://iamsahilralkar.github.io/document-hidden-demo/

Maybe we can just try 8 second jitters, only when document.hidden is false before moving to websockets.

@dckc
Copy link
Member Author

dckc commented Jul 13, 2023

nice work, @samsiegart and co!

These fixes were measured to reduce requests by 90% and traffic by 97%, IIRC.

@samsiegart please correct me if I'm off by much.

@samsiegart
Copy link
Contributor

samsiegart commented Jul 13, 2023

@dckc Yes, that's about right. Depends on which UI, as not every request is going through this new library and some have more requests to batch, but enough that we're under the 2 qps norm.

=========================

Dapp-inter RPC efficiency improvements, as measured on emerynet when using gov1 account with 9 open vaults...

Old dapp-inter using casting/proofs: 2800 requests, and 3.8MB per minute

New dapp-inter using batch queries: 36 requests and 150KB per minute

A 98.7% decrease in QPS, and 96% decrease in bandwidth!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working performance Performance related issues UI v1_triaged DO NOT USE vaults_triage DO NOT USE
Projects
None yet
Development

No branches or pull requests

4 participants