Skip to content
This repository was archived by the owner on Jun 30, 2022. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
7319089
have async execution so that the bot stays responsive while it's exec…
joao-paulo-parity Sep 16, 2021
b05bfe3
move tasks runner to Runner
joao-paulo-parity Sep 16, 2021
7de3189
exit earlier if benchmark has an error
joao-paulo-parity Sep 16, 2021
b6b77c3
fix payload exception handler
joao-paulo-parity Sep 16, 2021
e815751
wip
joao-paulo-parity Sep 16, 2021
d98eaad
wip
joao-paulo-parity Sep 16, 2021
acb7522
wip
joao-paulo-parity Sep 16, 2021
7e2a7a7
wip
joao-paulo-parity Sep 16, 2021
00d3e0d
wip
joao-paulo-parity Sep 16, 2021
d2ecf14
wip
joao-paulo-parity Sep 16, 2021
0801b08
wip
joao-paulo-parity Sep 16, 2021
63b1ae2
wip
joao-paulo-parity Sep 16, 2021
7a8198f
wip
joao-paulo-parity Sep 16, 2021
01081fa
wip
joao-paulo-parity Sep 16, 2021
41cc972
wip
joao-paulo-parity Sep 16, 2021
3551e4e
wip
joao-paulo-parity Sep 16, 2021
52fd19b
wip
joao-paulo-parity Sep 16, 2021
9e99369
wip
joao-paulo-parity Sep 16, 2021
c183cde
wip
joao-paulo-parity Sep 16, 2021
338c4af
wip
joao-paulo-parity Sep 16, 2021
fa971c6
wip
joao-paulo-parity Sep 16, 2021
be3b1db
wip
joao-paulo-parity Sep 16, 2021
72cb5ec
wip
joao-paulo-parity Sep 16, 2021
68251da
wip
joao-paulo-parity Sep 16, 2021
2512517
wip
joao-paulo-parity Sep 16, 2021
35ea565
wip
joao-paulo-parity Sep 16, 2021
be19715
wip
joao-paulo-parity Sep 17, 2021
6beed6d
wip
joao-paulo-parity Sep 17, 2021
405013f
wip
joao-paulo-parity Sep 17, 2021
c25fdbc
wip
joao-paulo-parity Sep 17, 2021
338dce2
wip
joao-paulo-parity Sep 17, 2021
aba873f
wip
joao-paulo-parity Sep 17, 2021
bf7ab50
wip
joao-paulo-parity Sep 17, 2021
fbc8c47
wip
joao-paulo-parity Sep 17, 2021
1f6e32e
wip
joao-paulo-parity Sep 17, 2021
17de0a0
wip
joao-paulo-parity Sep 17, 2021
00b0656
wip
joao-paulo-parity Sep 17, 2021
d08ce2b
wip
joao-paulo-parity Sep 17, 2021
590ecee
wip
joao-paulo-parity Sep 17, 2021
274c1d2
wip
joao-paulo-parity Sep 17, 2021
be68f38
wip
joao-paulo-parity Sep 17, 2021
569d00d
wip
joao-paulo-parity Sep 17, 2021
dac7323
wip
joao-paulo-parity Sep 17, 2021
ed05e7c
wip
joao-paulo-parity Sep 17, 2021
72b3797
wip
joao-paulo-parity Sep 17, 2021
6ef367a
clean
joao-paulo-parity Sep 17, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
wip
  • Loading branch information
joao-paulo-parity committed Sep 17, 2021
commit aba873fda84df8d2ec94cfe811aadf51071237ee
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ git
log.txt
runner_output.txt
payload.json
command_fifo
38 changes: 25 additions & 13 deletions runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ const execFileAsync = promisify(cp.execFile)
const existsAsync = promisify(fs.exists)

const runnerOutput = path.join(__dirname, "runner_output.txt")
const applicationLog = path.join(__dirname, "log.txt")
const commandFifo = path.join(__dirname, "command_fifo")

class Runner {
constructor(app) {
this.log = app.log
if (fs.existsSync(commandFifo)) {
cp.execFileSync("mkfifo", [commandFifo], { stdio: "ignore" })
}
}

async run(cmd, title) {
Expand All @@ -28,23 +33,30 @@ class Runner {

await writeFileAsync(runnerOutput, "")

// We the command is ran asynchronously so that the bot can still handle
// requests while it's executing. Previously we favored running the
// command synchronously so that there was less risk of having the Node.js
// process interfere or deprioritize the process' execution, but that it
// was observed that was unnecessary caution.
// Previously we've used cp.spawn for capturing the processes' streams
// but, again, having it execute directly in the shell reduces the
// likelihood of friction or overhead due to Node.js APIs.
// Since we should be redirecting the program's output streams to the
// systemd journal in the deployment, it's also relevant that we do not
// capture the process' streams here.
await execFileAsync(
// The command is ran asynchronously so that the bot can still handle
// requests while it's busy running some benchmark. Previously we favored
// running the command synchronously so that there was less risk of having
// the Node.js process interfere or deprioritize the process' execution,
// but that was that was later judged to be unnecessary caution based on
// the measurements.
// We've tried to cp.spawn for capturing the processes' streams but,
// again, such strategy might add execution overhead because then you'd
// have two processes competing for resources: the benchmark and the app.
// Running the proces in a shell is useful so that we simply wait until
// it's done and read the results afterwards, which is less likely to add
// any sort of friction that could introduce variation in the measurements
// compared to if one would run them manually.
const cmdProc = cp.spawn(
"bash",
["-c", `(${cmd}) 2>&1 | tee ${runnerOutput}`],
[
"-c",
`trap "echo > ${commandFifo}" EXIT; (${cmd}) 2>&1 | tee -a ${applicationLog} ${runnerOutput}`,
],
{ stdio: "ignore" },
)
cmdProc.unref()

await execFileAsync("cat", [commandFifo])
stdout = (await readFileAsync(runnerOutput)).toString()
} catch (err) {
error = true
Expand Down