Skip to content

Commit

Permalink
chore: temporarily disable registry writting on chunks (#160)
Browse files Browse the repository at this point in the history
# Description

Change on #159 didn't go
as planned
It's saving way too often.

Temporarily disabling to stop the current crashloop on staging.

The change above cause increased memory and cpu usage
https://g-0263500beb.grafana-workspace.eu-central-1.amazonaws.com/goto/P6O6S2kHR?orgId=1


![image](https://github.com/user-attachments/assets/aff14b00-02b9-4914-9842-7d5bf01bbe29)
  • Loading branch information
alfetopito authored Oct 4, 2024
1 parent 4978b50 commit 990dbb7
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/domain/polling/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const API_ERRORS_DROP: DropApiErrorsArray = [
// ApiErrors.IncompatibleSigningScheme - we control this in the watch-tower
// ApiErrors.AppDataHashMismatch - we never submit full appData

const CHUNK_SIZE = 20; // How many orders to process before saving
const CHUNK_SIZE = 50; // How many orders to process before saving

/**
* Watch for new blocks and check for orders to place
Expand All @@ -115,6 +115,7 @@ export async function checkForAndPlaceOrder(
let hasErrors = false;
let ownerCounter = 0;
let orderCounter = 0;
let updatedCount = 0;

const log = getLogger(
"checkForAndPlaceOrder:checkForAndPlaceOrder",
Expand All @@ -140,13 +141,13 @@ export async function checkForAndPlaceOrder(
orderCounter++;

// Check if we reached the chunk size
if (orderCounter % CHUNK_SIZE === 1 && orderCounter > 1) {
if (updatedCount % CHUNK_SIZE === 1 && updatedCount > 1) {
// Delete orders pending delete, if any
_deleteOrders(ordersPendingDelete, conditionalOrders, log, chainId);
// Reset tracker
ordersPendingDelete = [];

log.debug(`Processed ${orderCounter}, saving registry`);
log.debug(`Processed ${updatedCount}, saving registry`);

// Save the registry after processing each chunk
await registry.write();
Expand Down Expand Up @@ -231,6 +232,8 @@ export async function checkForAndPlaceOrder(
blockNumber: blockNumber,
result: pollResult,
};
// Order needs saving!
updatedCount++;

// Log the result
const unexpectedError =
Expand Down Expand Up @@ -290,6 +293,8 @@ function _deleteOrders(
log: LoggerWithMethods,
chainId: SupportedChainId
) {
log.debug(`${ordersPendingDelete.length} to delete`);

for (const conditionalOrder of ordersPendingDelete) {
const deleted = conditionalOrders.delete(conditionalOrder);
const action = deleted ? "Stop Watching" : "Failed to stop watching";
Expand Down

0 comments on commit 990dbb7

Please sign in to comment.