-
Notifications
You must be signed in to change notification settings - Fork 30
156 lines (142 loc) · 6.6 KB
/
benchmark.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
name: Benchmarks
on:
push:
branches:
- master
pull_request:
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request
# Run on the default actions, as well as labels applied
types: [ opened, synchronize, reopened, labeled ]
branches:
- "**"
# Required for PR comment permissions
# https://docs.github.com/en/rest/overview/permissions-required-for-github-apps?apiVersion=2022-11-28#repository-permissions-for-contents
permissions:
issues: write
jobs:
benchmark:
name: Run JMH benchmark
runs-on: kaldb-benchmark-latest-64cpu
# Run on any non-pull request, or pull requests that have the benchmark label
if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'benchmark')
steps:
- uses: actions/checkout@v3
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'corretto'
cache: 'maven'
# - name: Download benchmark data
# # AWS cli can be used if we want to host separate data - https://stackoverflow.com/questions/59166099/github-action-aws-cli
# run: |
# # https://github.com/opensearch-project/opensearch-benchmark-workloads
# curl -o documents-1k.json.bz2 https://opensearch-benchmark-workloads.s3.amazonaws.com/corpora/geopoint/documents-1k.json.bz2
- name: Run benchmark
run: |
mvn clean package -B -Dstyle.color=always -DskipTests=true --file pom.xml
java -Dlog4j.configurationFile=benchmarks/log4j2.xml -Xms8g -Xmx8g -jar benchmarks/target/benchmarks.jar -wi 5 -i 5 -f 1 -rf json
- name: Upload JHM results
uses: actions/upload-artifact@v3
with:
name: jmh-result.json
path: jmh-result.json
- name: Download previous benchmark data
uses: actions/cache/restore@v3
with:
restore-keys: |
jmh-result-data-
path: jmh-data.json
key: jmh-result-data
- name: Compile output results
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const rawThisRun = fs.readFileSync('jmh-result.json', 'utf8');
const rawPreviousResults = fs.existsSync('jmh-data.json') ? fs.readFileSync('jmh-data.json', 'utf8') : null;
const parsedThisRun = JSON.parse(rawThisRun);
const parsedPreviousResults = JSON.parse(rawPreviousResults);
const map = new Map();
parsedThisRun?.forEach(run => {
const runData = {
sha: context.sha,
timestamp: Date.now(),
data: run
}
if (map.has(run.benchmark)) {
map.get(run.benchmark).push(runData);
} else {
map.set(run.benchmark, [runData])
}
});
let lastRun = null;
if (parsedPreviousResults != null) {
Object.keys(parsedPreviousResults).forEach(key => {
parsedPreviousResults[key].sort((a, b) => { return b.timestamp - a.timestamp; });
if (lastRun == null || lastRun.timestamp < parsedPreviousResults[key][0].timestamp) {
lastRun = {
sha: parsedPreviousResults[key][0].sha,
timestamp: parsedPreviousResults[key][0].timestamp
}
}
if (map.has(key)) {
map.set(key, parsedPreviousResults[key].concat(map.get(key)));
} else {
map.set(key, parsedPreviousResults[key])
}
});
}
const header = `|Test|Previous ${lastRun?.sha}|Current ${context.sha}|Delta|`
const subheader = "|----|--------|--------|-----|"
let rows = "";
map.forEach((data, key) => {
const thisRun = data.find(run => run.sha === context.sha);
const mostRecentOtherRun = data.find(run => run.sha === lastRun?.sha);
const thisRunMetric = thisRun?.data.primaryMetric;
const mostRecentOtherRunMetric = mostRecentOtherRun?.data.primaryMetric;
const delta = (thisRunMetric?.score - mostRecentOtherRunMetric?.score) / mostRecentOtherRunMetric?.score * 100;
rows = rows + `|${key.replace("com.slack.kaldb.","")}|${mostRecentOtherRunMetric?.score.toFixed(1)} <sup>±${mostRecentOtherRunMetric?.scoreError.toFixed(1)}</sup>|${thisRunMetric?.score.toFixed(1)} <sup>±${thisRunMetric?.scoreError.toFixed(1)}</sup>|${delta?.toFixed(1)}%|\n`
});
const op = `${header}\n${subheader}\n${rows}`;
console.log(op);
fs.writeFileSync("jmh-data.json", JSON.stringify(Object.fromEntries(map)));
core.exportVariable('JMH_OP', op);
- name: Upload previous benchmark data
if: github.event_name != 'pull_request'
uses: actions/cache/save@v3
with:
path: jmh-data.json
key: jmh-result-data-${{ hashFiles('jmh-data.json') }}
- name: Append job summary
run: |
echo "${JMH_OP}" >> $GITHUB_STEP_SUMMARY
- name: Update comment on PR
if: github.event_name == 'pull_request'
uses: actions/github-script@v6
with:
script: |
const { JMH_OP } = process.env
// Get the existing comments.
const {data: comments} = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
});
// Find any comment already made by the bot.
const botComment = comments.find(comment => comment.body.includes("<!-- jmhBenchmark -->"))
if (botComment) {
await github.rest.issues.updateComment({
comment_id: botComment.id,
owner: context.repo.owner,
repo: context.repo.repo,
body: `${JMH_OP} <!-- jmhBenchmark -->`
});
} else {
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `${JMH_OP} <!-- jmhBenchmark -->`
});
}