near / near-indexer-events

7 stars 1 forks source link

Processing speed is too low for the number of sweatcoin events #21

Closed telezhnaya closed 1 year ago

telezhnaya commented 1 year ago

Starting from September 13th, we can process only 1 block per minute. We need to speed up the solution at least 120 times so that we can catch the latest block at some point of time.

Ideas:

telezhnaya commented 1 year ago

We may init absolute value lazily

draft of sql query to update values later, for future me:

with t as (select event_index, affected_account_id, contract_account_id, delta_amount, absolute_amount from coin_events 
where affected_account_id = 'mitchellcm.near'
order by event_index)
select event_index, delta_amount, 
sum(delta_amount) OVER (PARTITION BY affected_account_id, contract_account_id ORDER BY event_index) - 1000 AS cum_amt,
absolute_amount from t;
telezhnaya commented 1 year ago

There's no need to review the PR above, but we need to think carefully how should we fill absolute_amount. The speed of each block processing should be at least 2 blocks per second on the heaviest possible load. The main bottlenecks:

  1. write speed to the DB
  2. number of RPC queries per second

I see several options of filling absolute_amount with the resulting value

At first, we insert the data with NULL absolute_amount, the other process does UPDATE on each line to fill in the value

Pros:

Cons:

To sum up, I don't believe in this solution.

At first, we insert the data with NULL absolute_amount to the temp table, the other process does SELECT + INSERT on each line to fill in the (other) resulting table

Similar approach, but Pros:

Cons:

We keep absolute_amount NOT NULL, collect the events, save them somewhere (files? using event streaming?), the other process takes these files/events and perform inserts to the DB

Pros:

Cons:

I think this solution has the potential, but we need to discuss it.

telezhnaya commented 1 year ago

@frol suggested just to drop absolute_value column Pros:

Cons:

telezhnaya commented 1 year ago

We dropped absolute_value column