warmup caches on load

This commit is contained in:
Maximilian Schneider 2021-11-03 21:43:28 +00:00
parent 467740b401
commit f6de4f853e
3 changed files with 23 additions and 12 deletions

View File

@ -27,6 +27,7 @@
"@solana/web3.js": "^0.91.0",
"axios": "^0.21.1",
"cors": "^2.8.5",
"dayjs": "^1.10.7",
"express": "^4.17.1",
"lru-cache": "^5.1.0",
"tedis": "^0.1.12"

View File

@ -19,6 +19,7 @@ import {
import BN from 'bn.js'
import notify from './notify'
import LRUCache from 'lru-cache'
import * as dayjs from 'dayjs'
const redisUrl = new URL(process.env.REDISCLOUD_URL || 'redis://localhost:6379')
const host = redisUrl.hostname
@ -264,16 +265,20 @@ const priceScales: any = {
'COPE/USDC': 1000,
'COPE-PERP': 1000,
'ADA/USDC': 10000,
// 'ADA/USDC': 10000,
'ADA-PERP': 10000,
'MNGO/USDC': 10000,
'MNGO-PERP': 10000,
'USDT/USDC': 10000,
'USDT-PERP': 10000,
// 'USDT-PERP': 10000,
}
const cache = new LRUCache<string, Trade[]>(
parseInt(process.env.CACHE_LIMIT ?? '500')
)
const marketStores = {} as any
Object.keys(priceScales).forEach((marketName) => {
@ -283,19 +288,19 @@ Object.keys(priceScales).forEach((marketName) => {
password,
})
marketStores[marketName] = new RedisStore(conn, marketName)
})
const store = new RedisStore(conn, marketName)
marketStores[marketName] = store
const conn = new Tedis({
host,
port,
password,
// preload heavy markets
if (['SOL/USDC', 'SOL-PERP', 'BTC-PERP'].includes(marketName)) {
for (let i = 1; i < 60; ++i) {
const day = dayjs.default().subtract(i, 'days')
const key = store.keyForDay(+day)
store.loadTrades(key, cache).then(() => console.log('loaded', key))
}
}
})
const cache = new LRUCache<string, Trade[]>(
parseInt(process.env.CACHE_LIMIT ?? '500')
)
const app = express()
app.use(cors())

View File

@ -836,6 +836,11 @@ dateformat@~1.0.4-1.2.3:
get-stdin "^4.0.1"
meow "^3.3.0"
dayjs@^1.10.7:
version "1.10.7"
resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.10.7.tgz#2cf5f91add28116748440866a0a1d26f3a6ce468"
integrity sha512-P6twpd70BcPK34K26uJ1KT3wlhpuOAPoMwJzpsIWUxHZ7wpmbdZL/hQqBDfz7hGurYSa5PhzdhDHtt319hL3ig==
debug@2.6.9:
version "2.6.9"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"