-
Notifications
You must be signed in to change notification settings - Fork 8
Reduce contracts and deployments loading time #4233
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
base: development
Are you sure you want to change the base?
Conversation
- Handle migrations in parallel if needed - Add grid client cache - Add batch processing utility - Create grid clients in parallel with caching - Load contracts and node IDs in parallel for each machine - Process consumptions in batches - Process wireguard configs in batches
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use allsettled instead of promise.all for better error handling
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are many places that are still using promise.all
please make sure to use promise.allsettled everywhere
|
||
const normalizedContracts: NormalizedContract[] = []; | ||
for (const batch of batches) { | ||
const results = await Promise.all( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also here still using promise.all
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are other places please make sure to check them as well and replace the promise.all with promise.allsettled |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
partial review will review packages/playground/src/utils/load_deployment.ts
later
async function getNodeInfoWithCache(nodeIds: number[]) { | ||
const uncachedIds = nodeIds.filter(id => !nodeInfoCache.has(id)); | ||
if (uncachedIds.length > 0) { | ||
const newInfo = await getNodeInfo(uncachedIds, []); | ||
for (const [id, info] of Object.entries(newInfo)) { | ||
nodeInfoCache.set(Number(id), info); | ||
} | ||
} | ||
return nodeIds.map(id => nodeInfoCache.get(id)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- This function should be moved to the utils, imo
- Need to add error handling for getNodeInfo
- I have a concern about invalidating the cache as well
}) | ||
.then(res => res[0]) | ||
.catch(() => undefined); | ||
} finally { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a catch block; to at least log the errors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
const results = await Promise.allSettled([ | ||
loadVms(grid!), | ||
loadVms(updateGrid(grid!, { projectName: props.projectName.toLowerCase() })), | ||
showAllDeployments.value && props.projectName.toLowerCase() === ProjectName.VM.toLowerCase() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we may group the chunk 3 condition in both files into a separate variable then use it here
example
loadChunk3 ? loadVms(updateGrid(grid!, { projectName: "" })) : Promise.resolve({ count: 0, items: [], failedDeployments: [] }),
await Promise.allSettled([ | ||
chunk1.count > 0 && migrateModule(grid!.gateway), | ||
chunk2.count > 0 && migrateModule(grid!.gateway), | ||
chunk3.count > 0 && migrateModule(grid!.gateway), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i do not understand why we are calling the migrateModule threetimes with the same args,
also the && means if a chunk's count is 0, false is passed to Promise.allSettled() instead of a Promise, which works but isn't ideal.
please use
chunk1.count > 0 ? migrateModule(x) : Promise.resolve(),
const results: R[] = []; | ||
for (let i = 0; i < items.length; i += batchSize) { | ||
const batch = items.slice(i, i + batchSize); | ||
const batchResults = await processFn(batch); | ||
results.push(...batchResults); | ||
} | ||
return results; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can run the batches in parallel. Also please add error handling and unit test for it
- Call getTitalCost function only if there is no type defined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
partal review
- Remove get_nodeInfo_with_cache file and use it as a seperate function - Create test unit for getNodeInfoWithCache function - Extract helper functions to reduce the nesting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@0oM4R fixed now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test Scenarios:
- Test loading contracts time in contract page when have 20 contracts in the account and compare the old time Vs the new time.
- Test deploy a patch VMs and compare time for list deployment and for contract page.
- Deploy a Full VM with all networks enabled and compare listing time Vs new time after this PR.
- Test if we can have a failed deployment and how the list deployments time will react.
Additional tests:
- Test list deployment time when have VMs in grace period.
- Test list deployment time when have VMs on offline nodes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
listing contract have almost no enhancment
list deployment has a significant enhancement listing 10 micro vm deployments
add 31 name contract so the total now 100 node contract and 31 name contract
|
Tested:
|
@0oM4R I see the pagination error and loading deployments timeout exist in development, for the contracts I tested with more than 50 contracts, and it takes 13 seconds |
Description
Deployments:
Contracts:
Changes
Before: deployments loading time takes around 20 to 25 seconds
After: deployments, loading time takes around 15 to 20 seconds
Related Issues
Tested Scenarios
Check deployments loading
Time taken
in the console for deployments and contractsRamez test cases: #4233 (review)
Documentation PR
For UI changes, Please provide the Documentation PR on info_grid
To consider
Preliminary Checks:
UI Checks:
Code Quality Checks:
Testing Checklist
General Checklist