Skip to content

Commit

Permalink
fix: general fixes for gitlab ci
Browse files Browse the repository at this point in the history
- syntax: linting
- bench: benchmark working with swc now
- test: fixed test timing out in ci
- ci: added example and dummy benchmark
- ci: allow failure for `build:windows`
  • Loading branch information
tegefaulkes committed May 22, 2023
1 parent 5060ac7 commit 896e86f
Show file tree
Hide file tree
Showing 11 changed files with 424 additions and 45 deletions.
5 changes: 3 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ build:linux:
build:windows:
stage: build
needs: []
allow_failure: true
tags:
- windows
variables:
Expand Down Expand Up @@ -247,7 +248,7 @@ build:prerelease:
needs:
- build:dist
- build:linux
- build:windows
# - build:windows
- build:macos
# Don't interrupt publishing job
interruptible: false
Expand Down Expand Up @@ -332,7 +333,7 @@ release:distribution:
needs:
- build:dist
- build:linux
- build:windows
# - build:windows
- build:macos
- integration:merge
# Don't interrupt publishing job
Expand Down
30 changes: 30 additions & 0 deletions benches/dummy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import path from 'path';
import b from 'benny';
import { suiteCommon } from './utils';

async function main() {
// Running benchmark
const summary = b.suite(
path.basename(__filename, path.extname(__filename)),
b.add('add 1 + 1', async () => {
return 1 + 1;
}),
b.add('subtract 1 - 1', async () => {
return 1 - 1;
}),
b.add('multiply 1 * 1', async () => {
return 1 * 1;
}),
b.add('divide 1 / 1', async () => {
return 1 / 1;
}),
...suiteCommon,
);
return summary;
}

if (require.main === module) {
void main();
}

export default main;
5 changes: 5 additions & 0 deletions benches/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
import fs from 'fs';
import path from 'path';
import si from 'systeminformation';
import Stream1KB from './stream_1KB';
import Dummy from './dummy';

async function main(): Promise<void> {
await fs.promises.mkdir(path.join(__dirname, 'results'), { recursive: true });
// Running benches
await Stream1KB();
await Dummy();
const resultFilenames = await fs.promises.readdir(
path.join(__dirname, 'results'),
);
Expand Down
26 changes: 26 additions & 0 deletions benches/results/metrics.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# TYPE dummy_ops gauge
dummy_ops{name="add 1 + 1"} 11776647
dummy_ops{name="subtract 1 - 1"} 11685857
dummy_ops{name="multiply 1 * 1"} 12000931
dummy_ops{name="divide 1 / 1"} 11857267

# TYPE dummy_margin gauge
dummy_margin{name="add 1 + 1"} 0.55
dummy_margin{name="subtract 1 - 1"} 0.95
dummy_margin{name="multiply 1 * 1"} 0.48
dummy_margin{name="divide 1 / 1"} 0.58

# TYPE dummy_samples counter
dummy_samples{name="add 1 + 1"} 84
dummy_samples{name="subtract 1 - 1"} 84
dummy_samples{name="multiply 1 * 1"} 85
dummy_samples{name="divide 1 / 1"} 83

# TYPE stream_1KB_ops gauge
stream_1KB_ops{name="send 1Kib of data"} 176

# TYPE stream_1KB_margin gauge
stream_1KB_margin{name="send 1Kib of data"} 2.68

# TYPE stream_1KB_samples counter
stream_1KB_samples{name="send 1Kib of data"} 76
40 changes: 20 additions & 20 deletions benches/results/system.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
{
"cpu": {
"manufacturer": "AMD",
"brand": "Ryzen 7 2700X Eight-Core Processor",
"vendor": "AMD",
"family": "23",
"model": "8",
"stepping": "2",
"manufacturer": "Intel",
"brand": "Xeon® E3-1241 v3",
"vendor": "Intel",
"family": "6",
"model": "60",
"stepping": "3",
"revision": "",
"voltage": "",
"speed": 3.7,
"speedMin": 2.2,
"speedMax": 3.7,
"speed": 3.5,
"speedMin": 0.8,
"speedMax": 3.9,
"governor": "performance",
"cores": 16,
"physicalCores": 8,
"performanceCores": 8,
"cores": 8,
"physicalCores": 4,
"performanceCores": 4,
"efficiencyCores": 0,
"processors": 1,
"socket": "",
"flags": "fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb hw_pstate ssbd ibpb vmmcall fsgsbase bmi1 avx2 smep bmi2 rdseed adx smap clflushopt sha_ni xsaveopt xsavec xgetbv1 clzero irperf xsaveerptr arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif overflow_recov succor smca sev sev_es",
"flags": "fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts md_clear flush_l1d",
"virtualization": true,
"cache": {
"l1d": 262144,
"l1i": 524288,
"l2": 4194304,
"l3": 16777216
"l1d": 131072,
"l1i": 131072,
"l2": 1048576,
"l3": 8388608
}
},
"osInfo": {
"platform": "linux",
"distro": "nixos",
"release": "22.11",
"kernel": "6.1.23",
"kernel": "5.10.177",
"arch": "x64"
},
"system": {
"model": "System Product Name",
"manufacturer": "System manufacturer"
"model": "P7 Pro SE",
"manufacturer": "EUROCOM"
}
}
118 changes: 118 additions & 0 deletions benches/stream_1KB.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import type * as events from '../src/events';
import type { Host } from '../src/types';
import path from 'path';
import fs from 'fs';
import b from 'benny';
import Logger, { formatting, LogLevel, StreamHandler } from '@matrixai/logger';
import { suiteCommon } from './utils';
import QUICServer from '../src/QUICServer';
import * as testsUtils from '../tests/utils';
import QUICClient from '../src/QUICClient';

async function main() {
const logger = new Logger(`Stream1KB Bench`, LogLevel.WARN, [
new StreamHandler(
formatting.format`${formatting.level}:${formatting.keys}:${formatting.msg}`,
),
]);
// Setting up initial state
const crypto = {
key: await testsUtils.generateKey(),
ops: {
sign: testsUtils.sign,
verify: testsUtils.verify,
randomBytes: testsUtils.randomBytes,
},
};

const data1KiB = Buffer.alloc(1024, 0xf0);
const host = '::ffff:127.0.0.1' as Host;
const certChainPem = await fs.promises.readFile(
path.resolve(path.join(__dirname), '../tests/fixtures/certs/rsa1.crt'),
);
const privKeyPem = await fs.promises.readFile(
path.resolve(path.join(__dirname), '../tests/fixtures/certs/rsa1.key'),
);

const quicServer = new QUICServer({
config: {
tlsConfig: {
privKeyPem: privKeyPem.toString(),
certChainPem: certChainPem.toString(),
},
verifyPeer: false,
},
keepaliveIntervalTime: 1000,
crypto,
logger,
});
quicServer.addEventListener(
'connection',
async (e: events.QUICServerConnectionEvent) => {
const conn = e.detail;
conn.addEventListener(
'stream',
(streamEvent: events.QUICConnectionStreamEvent) => {
const stream = streamEvent.detail;
void Promise.allSettled([
(async () => {
// Consume data
for await (const _ of stream.readable) {
// Do nothing, only consume
}
})(),
(async () => {
// End writable immediately
await stream.writable.close();
})(),
]);
},
);
},
);
await quicServer.start({
host,
});
const client = await QUICClient.createQUICClient({
config: {
verifyPeer: false,
},
host,
port: quicServer.port,
crypto,
logger,
});
// Running benchmark
const summary = b.suite(
path.basename(__filename, path.extname(__filename)),
b.add('send 1Kib of data', async () => {
const stream = await client.connection.streamNew();
await Promise.all([
(async () => {
// Consume data
for await (const _ of stream.readable) {
// Do nothing, only consume
}
})(),
(async () => {
// Write data
const writer = stream.writable.getWriter();
await writer.write(data1KiB);
await writer.close();
})(),
]);
}),
...suiteCommon,
b.complete(async () => {
await quicServer.stop({ force: true });
await client.destroy({ force: true });
}),
);
return summary;
}

if (require.main === module) {
void main();
}

export default main;
1 change: 1 addition & 0 deletions benches/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './utils';
61 changes: 61 additions & 0 deletions benches/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import fs from 'fs';
import path from 'path';
import b from 'benny';
import { codeBlock } from 'common-tags';
import packageJson from '../../package.json';

const suiteCommon = [
b.cycle(),
b.complete(),
b.save({
file: (summary) => summary.name,
folder: path.join(__dirname, '../results'),
version: packageJson.version,
details: true,
}),
b.save({
file: (summary) => summary.name,
folder: path.join(__dirname, '../results'),
version: packageJson.version,
format: 'chart.html',
}),
b.complete((summary) => {
const filePath = path.join(
__dirname,
'../results',
summary.name + '_metrics.txt',
);
fs.writeFileSync(
filePath,
codeBlock`
# TYPE ${summary.name}_ops gauge
${summary.results
.map(
(result) =>
`${summary.name}_ops{name="${result.name}"} ${result.ops}`,
)
.join('\n')}
# TYPE ${summary.name}_margin gauge
${summary.results
.map(
(result) =>
`${summary.name}_margin{name="${result.name}"} ${result.margin}`,
)
.join('\n')}
# TYPE ${summary.name}_samples counter
${summary.results
.map(
(result) =>
`${summary.name}_samples{name="${result.name}"} ${result.samples}`,
)
.join('\n')}
` + '\n',
);
// eslint-disable-next-line no-console
console.log('\nSaved to:', path.resolve(filePath));
}),
];

export { suiteCommon };
Loading

0 comments on commit 896e86f

Please sign in to comment.