Skip to content

Commit 9d0fd98

Browse files
committed
add mysql
1 parent f912a3d commit 9d0fd98

File tree

6 files changed

+156
-26
lines changed

6 files changed

+156
-26
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
CREATE DATABASE mydb;
2+
USE mydb
3+
4+
-- SQL script to create the 'users' table and insert initial data.
5+
6+
-- 1. Create the 'users' table
7+
-- This table stores basic user information.
8+
-- 'id' is the primary key and will automatically increment for each new record.
9+
-- 'name' stores the user's name, up to 255 characters.
10+
-- 'age' stores the user's age as an integer.
11+
12+
CREATE TABLE users (
13+
id INT PRIMARY KEY AUTO_INCREMENT,
14+
name VARCHAR(255) NOT NULL,
15+
age INT
16+
);
17+
18+
-- 2. Insert 5 rows into the 'users' table
19+
-- Populating the table with some sample data.
20+
21+
INSERT INTO users (name, age) VALUES ('Alice Johnson', 28);
22+
INSERT INTO users (name, age) VALUES ('Bob Smith', 45);
23+
INSERT INTO users (name, age) VALUES ('Charlie Brown', 32);
24+
INSERT INTO users (name, age) VALUES ('Diana Prince', 25);
25+
INSERT INTO users (name, age) VALUES ('Ethan Hunt', 41);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
services:
2+
db:
3+
image: mysql:8
4+
restart: always
5+
container_name: node-overhead-gh-action-mysql
6+
ports:
7+
- '3306:3306'
8+
environment:
9+
MYSQL_ROOT_PASSWORD: password
10+
volumes:
11+
# - ./db/data:/var/lib/mysql
12+
- ./db/init:/docker-entrypoint-initdb.d/:ro

dev-packages/node-overhead-gh-action/lib/getOverheadMeasurements.mjs

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { spawn } from 'child_process';
1+
import { execSync, spawn } from 'child_process';
22
import { dirname, join } from 'path';
33
import treeKill from 'tree-kill';
44
import { fileURLToPath } from 'url';
@@ -117,6 +117,47 @@ async function startAutocannonProcess(autocannonCommand) {
117117
});
118118
}
119119

120+
function startDb() {
121+
const closeDb = () => {
122+
execSync('yarn db:down', {
123+
shell: true,
124+
cwd: packageRoot,
125+
});
126+
};
127+
128+
// Ensure eventually open DB is closed fist
129+
closeDb();
130+
131+
return new Promise((resolve, reject) => {
132+
const child = spawn('yarn db:up', {
133+
shell: true,
134+
cwd: packageRoot,
135+
});
136+
137+
const timeout = setTimeout(() => {
138+
closeDb();
139+
reject(new Error('Timed out waiting for docker-compose'));
140+
}, 60000);
141+
142+
const readyMatch = 'port: 3306';
143+
144+
function newData(data) {
145+
const text = data.toString('utf8');
146+
log(text);
147+
148+
if (text.includes(readyMatch)) {
149+
child.stdout.removeAllListeners();
150+
child.stderr.removeAllListeners();
151+
clearTimeout(timeout);
152+
resolve(closeDb);
153+
}
154+
}
155+
156+
child.stdout.on('data', newData);
157+
child.stderr.on('data', newData);
158+
});
159+
}
160+
120161
async function getOverheadMeasurements() {
121162
const GET = {
122163
baseline: await getMeasurements(undefined, 'yarn test:get'),
@@ -130,19 +171,31 @@ async function getOverheadMeasurements() {
130171
withInstrumentErrorOnly: await getMeasurements('./src/instrument-error-only.mjs', 'yarn test:post'),
131172
};
132173

174+
const MYSQL = {
175+
baseline: await getMeasurements(undefined, 'yarn test:mysql'),
176+
withInstrument: await getMeasurements('./src/instrument.mjs', 'yarn test:mysql'),
177+
withInstrumentErrorOnly: await getMeasurements('./src/instrument-error-only.mjs', 'yarn test:mysql'),
178+
};
179+
133180
return {
134181
GET,
135182
POST,
183+
MYSQL,
136184
};
137185
}
138186

139187
export async function getAveragedOverheadMeasurements() {
188+
const closeDb = await startDb();
189+
const repeat = process.env.REPEAT ? parseInt(process.env.REPEAT) : 1;
190+
140191
const results = [];
141-
for (let i = 0; i < 2; i++) {
192+
for (let i = 0; i < repeat; i++) {
142193
const result = await getOverheadMeasurements();
143194
results.push(result);
144195
}
145196

197+
closeDb();
198+
146199
// Calculate averages for each scenario
147200
const averaged = {
148201
GET: {
@@ -159,6 +212,13 @@ export async function getAveragedOverheadMeasurements() {
159212
results.reduce((sum, r) => sum + r.POST.withInstrumentErrorOnly, 0) / results.length,
160213
),
161214
},
215+
MYSQL: {
216+
baseline: Math.floor(results.reduce((sum, r) => sum + r.MYSQL.baseline, 0) / results.length),
217+
withInstrument: Math.floor(results.reduce((sum, r) => sum + r.MYSQL.withInstrument, 0) / results.length),
218+
withInstrumentErrorOnly: Math.floor(
219+
results.reduce((sum, r) => sum + r.MYSQL.withInstrumentErrorOnly, 0) / results.length,
220+
),
221+
},
162222
};
163223

164224
return averaged;

dev-packages/node-overhead-gh-action/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,27 @@
1414
"start:sentry": "node --import ./src/instrument.mjs ./src/app.mjs",
1515
"start:sentry-error-only": "node --import ./src/instrument-error-only.mjs ./src/app.mjs",
1616
"test:get": "autocannon --json -c 100 -p 10 -d 10 -W [ -c 100 -d 5] http://localhost:3030/test-get",
17+
"test:mysql": "autocannon --json -c 100 -p 10 -d 10 -W [ -c 100 -d 5] http://localhost:3030/test-mysql",
1718
"test:post": "autocannon --json -m POST -b \"{\\\"data\\\":\\\"test\\\"}\" --headers \"Content-type: application/json\" -c 100 -p 10 -d 10 -W [ -c 100 -d 5] http://localhost:3030/test-post",
1819
"clean": "rimraf -g **/node_modules",
20+
"db:up": "docker compose up",
21+
"db:down": "docker compose down --volumes",
1922
"lint": "eslint . --format stylish",
2023
"fix": "eslint . --format stylish --fix"
2124
},
2225
"dependencies": {
2326
"@sentry/node": "10.8.0",
24-
"express": "^4.21.1"
27+
"express": "^4.21.1",
28+
"mysql2": "^3.14.4"
2529
},
2630
"devDependencies": {
27-
"autocannon": "^8.0.0",
2831
"@actions/artifact": "2.1.11",
2932
"@actions/core": "1.10.1",
3033
"@actions/exec": "1.1.1",
3134
"@actions/github": "^5.0.0",
3235
"@actions/glob": "0.4.0",
3336
"@actions/io": "1.1.3",
37+
"autocannon": "^8.0.0",
3438
"markdown-table": "3.0.3",
3539
"tree-kill": "1.2.2"
3640
},

dev-packages/node-overhead-gh-action/src/app.mjs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
11
import * as Sentry from '@sentry/node';
22
import express from 'express';
3+
import mysql from 'mysql2/promise';
34

45
const app = express();
56
const port = 3030;
67

8+
const pool = mysql.createPool({
9+
user: 'root',
10+
password: 'password',
11+
host: 'localhost',
12+
database: 'mydb',
13+
port: 3306,
14+
waitForConnections: true,
15+
connectionLimit: 10,
16+
maxIdle: 10, // max idle connections, the default value is the same as `connectionLimit`
17+
idleTimeout: 60000, // idle connections timeout, in milliseconds, the default value 60000
18+
queueLimit: 0,
19+
enableKeepAlive: true,
20+
keepAliveInitialDelay: 0,
21+
});
22+
723
app.use(express.json());
824

925
app.get('/test-get', function (req, res) {
@@ -15,6 +31,12 @@ app.post('/test-post', function (req, res) {
1531
res.send(generateResponse(body));
1632
});
1733

34+
app.get('/test-mysql', function (_req, res) {
35+
pool.query('SELECT * from users').then(([users]) => {
36+
res.send({ version: 'v1', users });
37+
});
38+
});
39+
1840
Sentry.setupExpressErrorHandler(app);
1941

2042
app.listen(port, () => {

yarn.lock

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18805,6 +18805,13 @@ [email protected], iconv-lite@^0.6.2, iconv-lite@^0.6.3:
1880518805
dependencies:
1880618806
safer-buffer ">= 2.1.2 < 3.0.0"
1880718807

18808+
iconv-lite@^0.7.0:
18809+
version "0.7.0"
18810+
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.7.0.tgz#c50cd80e6746ca8115eb98743afa81aa0e147a3e"
18811+
integrity sha512-cf6L2Ds3h57VVmkZe+Pn+5APsT7FpqJtEhhieDCvrE2MK5Qk9MyffgQyuxQTm6BChfeZNtcOLHp9IcWRVcIcBQ==
18812+
dependencies:
18813+
safer-buffer ">= 2.1.2 < 3.0.0"
18814+
1880818815
icss-utils@^5.0.0, icss-utils@^5.1.0:
1880918816
version "5.1.0"
1881018817
resolved "https://registry.yarnpkg.com/icss-utils/-/icss-utils-5.1.0.tgz#c6be6858abd013d768e98366ae47e25d5887b1ae"
@@ -22600,15 +22607,15 @@ mute-stream@~1.0.0:
2260022607
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-1.0.0.tgz#e31bd9fe62f0aed23520aa4324ea6671531e013e"
2260122608
integrity sha512-avsJQhyd+680gKXyG/sQc0nXaC6rBkPOfyHYcFb9+hdkqQkR9bdnkJ0AMZhke0oesPqIO+mFFJ+IdBc7mst4IA==
2260222609

22603-
mysql2@^3.11.3:
22604-
version "3.11.3"
22605-
resolved "https://registry.yarnpkg.com/mysql2/-/mysql2-3.11.3.tgz#8291e6069a0784310846f6437b8527050dfc10c4"
22606-
integrity sha512-Qpu2ADfbKzyLdwC/5d4W7+5Yz7yBzCU05YWt5npWzACST37wJsB23wgOSo00qi043urkiRwXtEvJc9UnuLX/MQ==
22610+
mysql2@^3.11.3, mysql2@^3.14.4:
22611+
version "3.14.4"
22612+
resolved "https://registry.yarnpkg.com/mysql2/-/mysql2-3.14.4.tgz#36e33a8d33820a299fb9e9221486310b1a4c8767"
22613+
integrity sha512-Cs/jx3WZPNrYHVz+Iunp9ziahaG5uFMvD2R8Zlmc194AqXNxt9HBNu7ZsPYrUtmJsF0egETCWIdMIYAwOGjL1w==
2260722614
dependencies:
2260822615
aws-ssl-profiles "^1.1.1"
2260922616
denque "^2.1.0"
2261022617
generate-function "^2.3.1"
22611-
iconv-lite "^0.6.3"
22618+
iconv-lite "^0.7.0"
2261222619
long "^5.2.1"
2261322620
lru.min "^1.0.0"
2261422621
named-placeholders "^1.1.3"
@@ -28408,7 +28415,7 @@ string-template@~0.2.1:
2840828415
is-fullwidth-code-point "^3.0.0"
2840928416
strip-ansi "^6.0.1"
2841028417

28411-
[email protected], "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3:
28418+
"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3:
2841228419
version "4.2.3"
2841328420
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
2841428421
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -28518,13 +28525,6 @@ stringify-object@^3.2.1:
2851828525
dependencies:
2851928526
ansi-regex "^5.0.1"
2852028527

28521-
[email protected], strip-ansi@^6.0.0, strip-ansi@^6.0.1:
28522-
version "6.0.1"
28523-
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
28524-
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
28525-
dependencies:
28526-
ansi-regex "^5.0.1"
28527-
2852828528
strip-ansi@^3.0.0:
2852928529
version "3.0.1"
2853028530
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-3.0.1.tgz#6a385fb8853d952d5ff05d0e8aaf94278dc63dcf"
@@ -28546,6 +28546,13 @@ strip-ansi@^5.1.0, strip-ansi@^5.2.0:
2854628546
dependencies:
2854728547
ansi-regex "^4.1.0"
2854828548

28549+
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
28550+
version "6.0.1"
28551+
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
28552+
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
28553+
dependencies:
28554+
ansi-regex "^5.0.1"
28555+
2854928556
strip-ansi@^7.0.1, strip-ansi@^7.1.0:
2855028557
version "7.1.0"
2855128558
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45"
@@ -28695,7 +28702,7 @@ [email protected], stylus@^0.59.0:
2869528702
sax "~1.2.4"
2869628703
source-map "^0.7.3"
2869728704

28698-
sucrase@^3.27.0, sucrase@^3.35.0, sucrase@getsentry/sucrase#es2020-polyfills:
28705+
sucrase@^3.27.0, sucrase@^3.35.0:
2869928706
version "3.36.0"
2870028707
resolved "https://codeload.github.com/getsentry/sucrase/tar.gz/fd682f6129e507c00bb4e6319cc5d6b767e36061"
2870128708
dependencies:
@@ -31582,19 +31589,19 @@ [email protected]:
3158231589
string-width "^4.1.0"
3158331590
strip-ansi "^6.0.0"
3158431591

31585-
wrap-ansi@7.0.0, wrap-ansi@^7.0.0:
31586-
version "7.0.0"
31587-
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
31588-
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
31592+
wrap-ansi@^6.0.1:
31593+
version "6.2.0"
31594+
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-6.2.0.tgz#e9393ba07102e6c91a3b221478f0257cd2856e53"
31595+
integrity sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==
3158931596
dependencies:
3159031597
ansi-styles "^4.0.0"
3159131598
string-width "^4.1.0"
3159231599
strip-ansi "^6.0.0"
3159331600

31594-
wrap-ansi@^6.0.1:
31595-
version "6.2.0"
31596-
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-6.2.0.tgz#e9393ba07102e6c91a3b221478f0257cd2856e53"
31597-
integrity sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==
31601+
wrap-ansi@^7.0.0:
31602+
version "7.0.0"
31603+
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
31604+
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
3159831605
dependencies:
3159931606
ansi-styles "^4.0.0"
3160031607
string-width "^4.1.0"

0 commit comments

Comments
 (0)