Skip to content

Commit 24a72ee

Browse files
committed
chore: bump processing batch size 10x
1 parent 0ea81a7 commit 24a72ee

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

ui/src/app/api/messages/batch/route.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { createReadStream } from "fs";
22
import { NextResponse } from "next/server";
33
import readline from "readline";
44

5-
import { getSetSimulationMaxTime } from "@/app/queries";
65
import { IServerMessage } from "@/components/Graph/types";
76
import { ISimulationAggregatedDataState } from "@/contexts/GraphContext/types";
87
import { messagesPath } from "../../utils";
@@ -78,7 +77,7 @@ export async function GET(req: Request, res: Response) {
7877
let interval: Timer | undefined;
7978
const eventBuffer: string[] = [];
8079
let simulationDone = false;
81-
const maxTime = await getSetSimulationMaxTime();
80+
let isProcessing = false;
8281

8382
const stream = new ReadableStream({
8483
cancel() {
@@ -94,6 +93,11 @@ export async function GET(req: Request, res: Response) {
9493
};
9594

9695
interval = setInterval(() => {
96+
if (isProcessing) {
97+
return;
98+
}
99+
100+
isProcessing = true;
97101
if (eventBuffer.length === 0 && simulationDone) {
98102
clearInterval(interval);
99103
rl.close();
@@ -104,7 +108,7 @@ export async function GET(req: Request, res: Response) {
104108

105109
try {
106110
// Process 10k events at a time.
107-
const batch = eventBuffer.splice(0, 10000);
111+
const batch = eventBuffer.splice(0, 100000);
108112
for (const line of batch) {
109113
const data: IServerMessage = JSON.parse(line);
110114
processMessage(data, aggregatedData);
@@ -117,9 +121,12 @@ export async function GET(req: Request, res: Response) {
117121
};
118122

119123
controller.enqueue(`data: ${JSON.stringify(serializedData)}\n\n`);
124+
isProcessing = false;
120125
} catch (e) {
121126
controller.error(e);
127+
isProcessing = false;
122128
}
129+
123130
}, 100);
124131

125132
rl.on("line", (line: string) => {

ui/src/app/queries.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export const getSetSimulationMaxTime = async (): Promise<number> => {
7878
export const getSimulationTopography = async () => {
7979
const filePath = path.resolve(
8080
__dirname,
81-
"../../../../../sim-rs/test_data/thousand.toml",
81+
"../../../../../sim-rs/test_data/realistic.toml",
8282
);
8383
const fileStream = createReadStream(filePath, {
8484
encoding: "utf8",

0 commit comments

Comments
 (0)