Skip to content

Commit

Permalink
add client side execution time tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
Schlauer-Hax committed Dec 3, 2024
1 parent acb62e0 commit 9a425dc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ public void handleMessage(String message) {
String data = String.join(":",Arrays.copyOfRange(messagearray, 4, messagearray.length));
System.out.println("Running solution "+name+" with runid "+runid);
CompletableFuture.supplyAsync(() ->
solutionRunner.runClass(name, data)).thenAccept((result) -> {
client.send("aocclient:java:result:"+runid+":"+ Arrays.toString(result));
});
long start = System.nanoTime();
solutionRunner.runClass(name, data)).thenAccept((result) -> {
long end = System.nanoTime();
client.send("aocclient:java:result:"+runid+":"+(end-start)/(double)10e6":"+ Arrays.toString(result));
}
);
}
}

Expand Down
4 changes: 3 additions & 1 deletion clients/typescript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ function startWebsocket() {
const data = split.slice(4).join(':');
const solution = split[3];
console.log(`running ${solution} with runid ${runid}`);
const startTime = performance.now();
const result = await runner.run(solution, data);
const time = performance.now() - startTime;
console.log(`result for ${solution} with runid ${runid}: ${result}`)
ws.send(`aocclient:ts:result:${runid}:[${result[0]}, ${result[1]}]`);
ws.send(`aocclient:ts:result:${runid}:${time}:[${result[0]}, ${result[1]}]`);
}
});

Expand Down
9 changes: 5 additions & 4 deletions server/apiserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class ApiServer {
const { socket: ws, response } = Deno.upgradeWebSocket(req);

ws.onmessage = (e) => {
const msg = e.data.toString();
const msg: string = e.data.toString();
const split = msg.split(':');

// Code Runner Requests
Expand All @@ -30,10 +30,11 @@ export default class ApiServer {
}
if (messagedata === 'result') {
const id = Number(split[3]);
const result = split.slice(4).join(':');
console.log(`${clientname} got result ${result} with runid ${id}`)
const time = Number(split[4]);
const result = split.slice(5).join(':');
console.log(`${clientname} got result ${result} with runid ${id} in ${time}ms`);
const run = webserver.runs.find(run => run[0] === id)!;
run[1].send(JSON.stringify({ type: 'result', data: result, time: new Date().getTime() - run[2] }));
run[1].send(JSON.stringify({ type: 'result', data: result, time: time }));
}
if (messagedata === 'solutions') {
webserver.solutions = webserver.solutions.filter(solution => solution[0] !== clientname)
Expand Down
4 changes: 2 additions & 2 deletions server/webserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ApiServer from "./apiserver.ts";
export default class WebServer {
solutions: [string, string[]][] = [];
clients: WebSocket[] = [];
runs: [number, WebSocket, number][] = [];
runs: [number, WebSocket][] = [];

startServer(apiserver: ApiServer) {
const app = new Application();
Expand All @@ -30,7 +30,7 @@ export default class WebServer {

if (!(input && solution)) return;
const id = Math.round(Math.random() * 100000)
this.runs.push([id, ws, new Date().getTime()]);
this.runs.push([id, ws]);
const clientname = this.solutions.find(solutiondata => solutiondata[1].includes(solution))![0];
console.log(`running ${solution} with runid ${id} on runner ${clientname}`)
const coderunner = apiserver.clients.find(client => client[0] === clientname);
Expand Down

0 comments on commit 9a425dc

Please sign in to comment.