-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Performance test fixes and optimizations (#159)
* Improve signed data performance, improve logs * Schedule pushing signed data after they are fetched * Fix package.json * Only sign and push signed data when the API request is success * Log short info level for incoming requests
- Loading branch information
Showing
15 changed files
with
91 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,14 @@ | ||
import { initiateFetchingBeaconData } from './fetch-beacon-data'; | ||
import { initiateHeartbeat } from './heartbeat'; | ||
import { initiateSignedApiUpdateLoops } from './fetch-beacon-data'; | ||
import { initiateHeartbeatLoop } from './heartbeat'; | ||
import { initializeState } from './state'; | ||
import { initiateUpdatingSignedApi } from './update-signed-api'; | ||
import { loadConfig } from './validation/config'; | ||
|
||
const main = async () => { | ||
const config = await loadConfig(); | ||
initializeState(config); | ||
|
||
initiateFetchingBeaconData(); | ||
initiateUpdatingSignedApi(); | ||
initiateHeartbeat(); | ||
initiateSignedApiUpdateLoops(); | ||
initiateHeartbeatLoop(); | ||
}; | ||
|
||
void main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,6 @@ | ||
import { get, isEmpty, uniq } from 'lodash'; | ||
import { pushSignedData } from './api-requests/signed-api'; | ||
import type { SignedApiUpdate } from './validation/schema'; | ||
|
||
import { postSignedApiData } from './api-requests/signed-api'; | ||
import { SIGNED_DATA_PUSH_POLLING_INTERVAL } from './constants'; | ||
import { logger } from './logger'; | ||
import { getState } from './state'; | ||
import { sleep } from './utils'; | ||
import type { TemplateId } from './validation/schema'; | ||
|
||
// <Signed API Provider, <Update Delay, List of template IDs>> | ||
type SignedApiUpdateDelayTemplateIdsMap = Record<string, Record<number, TemplateId[]>>; | ||
|
||
export interface SignedApiNameUpdateDelayGroup { | ||
signedApiName: string; | ||
templateIds: TemplateId[]; | ||
updateDelay: number; | ||
} | ||
|
||
export const initiateUpdatingSignedApi = () => { | ||
logger.debug('Initiating updating signed API.'); | ||
const { config } = getState(); | ||
|
||
const signedApiUpdateDelayTemplateIdsMap = | ||
config.triggers.signedApiUpdates.reduce<SignedApiUpdateDelayTemplateIdsMap>((acc, signedApiUpdate) => { | ||
if (isEmpty(signedApiUpdate.templateIds)) return acc; | ||
|
||
return { | ||
...acc, | ||
[signedApiUpdate.signedApiName]: { | ||
...acc[signedApiUpdate.signedApiName], | ||
[signedApiUpdate.updateDelay]: uniq([ | ||
...get(acc, [signedApiUpdate.signedApiName, signedApiUpdate.updateDelay], []), | ||
...signedApiUpdate.templateIds, | ||
]), | ||
}, | ||
}; | ||
}, {}); | ||
|
||
const signedApiUpdateDelayGroups: SignedApiNameUpdateDelayGroup[] = Object.entries( | ||
signedApiUpdateDelayTemplateIdsMap | ||
).flatMap(([signedApiName, updateDelayTemplateIds]) => | ||
Object.entries(updateDelayTemplateIds).map(([updateDelay, templateIds]) => ({ | ||
signedApiName, | ||
updateDelay: Number.parseInt(updateDelay, 10), | ||
templateIds, | ||
})) | ||
); | ||
|
||
signedApiUpdateDelayGroups.map(async (element) => updateSignedApiInLoop(element)); | ||
}; | ||
|
||
export const updateSignedApiInLoop = async (signedApiNameUpdateDelayGroup: SignedApiNameUpdateDelayGroup) => { | ||
while (true) { | ||
await postSignedApiData(signedApiNameUpdateDelayGroup); | ||
await sleep(SIGNED_DATA_PUSH_POLLING_INTERVAL); | ||
} | ||
export const schedulePushingSignedData = (signedApiUpdate: SignedApiUpdate) => { | ||
setTimeout(async () => pushSignedData(signedApiUpdate), signedApiUpdate.updateDelay); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.