Skip to content

Commit 848e875

Browse files
committed
dynamic rater prefetch
1 parent e6ff421 commit 848e875

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

svc/cycler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ async function cycle() {
3434
while (true) {
3535
// Start with a base number for gcdata/rater reqs and add additional retrievers based on parser capacity
3636
// Each retriever handles about 1 req/sec so divide by the avg number of seconds per parse
37-
const count = Math.ceil((await getCapacity()) / 12) + 4;
37+
const count = Math.ceil((await getCapacity()) / 12) + 5;
3838
shuffle(zones);
3939
const zone = zones[0];
4040
const config = {

svc/parser.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import config from '../config.ts';
99
import { runReliableQueue } from './store/queue.ts';
1010
import c from 'ansi-colors';
11-
import { buildReplayUrl, redisCount } from './util/utility.ts';
11+
import { buildReplayUrl, getParserCapacity, redisCount } from './util/utility.ts';
1212
import redis from './store/redis.ts';
1313
import { apiFetcher } from './fetcher/getApiData.ts';
1414
import { parsedFetcher } from './fetcher/getParsedData.ts';
@@ -17,8 +17,6 @@ import { getPGroup } from './util/pgroup.ts';
1717
import moment from 'moment';
1818
import { queueReconcile } from './util/insert.ts';
1919

20-
const { PARSER_PARALLELISM } = config;
21-
2220
async function parseProcessor(job: ParseJob, metadata: JobMetadata) {
2321
const start = Date.now();
2422
let apiTime = 0;
@@ -164,15 +162,9 @@ async function parseProcessor(job: ParseJob, metadata: JobMetadata) {
164162
}
165163
}
166164
}
167-
async function getCapacity() {
168-
if (config.USE_SERVICE_REGISTRY) {
169-
return redis.zcard('registry:parser');
170-
}
171-
return Number(PARSER_PARALLELISM);
172-
}
173165
runReliableQueue(
174166
'parse',
175-
Number(PARSER_PARALLELISM),
167+
Number(config.PARSER_PARALLELISM),
176168
parseProcessor,
177-
getCapacity,
169+
getParserCapacity,
178170
);

svc/rater.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { gcFetcher } from './fetcher/getGcData.ts';
22
import db from './store/db.ts';
3-
import { average, isRadiant, redisCount } from './util/utility.ts';
3+
import { average, getRetrieverCapacity, isRadiant, redisCount } from './util/utility.ts';
44

55
const DEFAULT_RATING = 4000;
66
const kFactor = 32;
@@ -98,7 +98,8 @@ async function prefetchGcData() {
9898
const { rows } = await db.raw<{
9999
rows: { match_seq_num: number; match_id: number; pgroup: PGroup }[];
100100
}>(
101-
'SELECT match_seq_num, match_id, pgroup from rating_queue WHERE gcdata IS NULL ORDER BY match_seq_num LIMIT 5',
101+
'SELECT match_seq_num, match_id, pgroup from rating_queue WHERE gcdata IS NULL ORDER BY match_seq_num LIMIT ?',
102+
[await getRetrieverCapacity()]
102103
);
103104
if (rows.length) {
104105
// Attempt to fetch for each

svc/util/utility.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,17 @@ function makeUrlArray(input: string) {
725725
return output;
726726
}
727727

728-
export function getRetrieverCount() {
728+
export async function getParserCapacity() {
729+
if (config.USE_SERVICE_REGISTRY) {
730+
return redis.zcard('registry:parser');
731+
}
732+
return Number(config.PARSER_PARALLELISM);
733+
}
734+
735+
export async function getRetrieverCapacity() {
736+
if (config.USE_SERVICE_REGISTRY) {
737+
return redis.zcard('registry:retriever');
738+
}
729739
return RETRIEVER_ARRAY.length;
730740
}
731741

0 commit comments

Comments
 (0)