@nestia/benchmark 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/lib/DynamicBenchmarker.d.ts +176 -0
- package/lib/DynamicBenchmarker.js +577 -0
- package/lib/DynamicBenchmarker.js.map +1 -0
- package/lib/IBenchmarkEvent.d.ts +9 -0
- package/lib/IBenchmarkEvent.js +3 -0
- package/lib/IBenchmarkEvent.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +19 -0
- package/lib/index.js.map +1 -0
- package/lib/internal/IBenchmarkMaster.d.ts +4 -0
- package/lib/internal/IBenchmarkMaster.js +3 -0
- package/lib/internal/IBenchmarkMaster.js.map +1 -0
- package/lib/internal/IBenchmarkServant.d.ts +7 -0
- package/lib/internal/IBenchmarkServant.js +3 -0
- package/lib/internal/IBenchmarkServant.js.map +1 -0
- package/package.json +52 -0
- package/src/DynamicBenchmarker.ts +486 -0
- package/src/IBenchmarkEvent.ts +10 -0
- package/src/index.ts +2 -0
- package/src/internal/IBenchmarkMaster.ts +4 -0
- package/src/internal/IBenchmarkServant.ts +8 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Jeongho Nam
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { IConnection } from "@nestia/fetcher";
|
|
2
|
+
import { WorkerServer } from "tgrid";
|
|
3
|
+
import { IBenchmarkMaster } from "./internal/IBenchmarkMaster";
|
|
4
|
+
import { IBenchmarkServant } from "./internal/IBenchmarkServant";
|
|
5
|
+
/**
|
|
6
|
+
* Dynamic benchmark executor running prefixed functions.
|
|
7
|
+
*
|
|
8
|
+
* `DynamicBenchmarker` is composed with two programs,
|
|
9
|
+
* {@link DynamicBenchmarker.master} and
|
|
10
|
+
* {@link DynamicBenchmarker.servant servants}. The master program creates
|
|
11
|
+
* multiple servant programs, and the servant programs execute the prefixed
|
|
12
|
+
* functions in parallel. When the pre-congirued count of requests are all
|
|
13
|
+
* completed, the master program collects the results and returns them.
|
|
14
|
+
*
|
|
15
|
+
* Therefore, when you want to benchmark the performance of a backend server,
|
|
16
|
+
* you have to make two programs; one for calling the
|
|
17
|
+
* {@link DynamicBenchmarker.master} function, and the other for calling the
|
|
18
|
+
* {@link DynamicBenchmarker.servant} function. Also, never forget to write
|
|
19
|
+
* the path of the servant program to the
|
|
20
|
+
* {@link DynamicBenchmarker.IMasterProps.servant} property.
|
|
21
|
+
*
|
|
22
|
+
* Also, you when you complete the benchmark execution through the
|
|
23
|
+
* {@link DynamicBenchmarker.master} and {@link DynamicBenchmarker.servant}
|
|
24
|
+
* functions, you can convert the result to markdown content by using the
|
|
25
|
+
* {@link DynamicBenchmarker.markdown} function.
|
|
26
|
+
*
|
|
27
|
+
* Additionally, if you hope to see some utilization cases,
|
|
28
|
+
* see the below example tagged links.
|
|
29
|
+
*
|
|
30
|
+
* @example https://github.com/samchon/nestia-start/blob/master/test/benchmaark/index.ts
|
|
31
|
+
* @example https://github.com/samchon/backend/blob/master/test/benchmark/index.ts
|
|
32
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
33
|
+
*/
|
|
34
|
+
export declare namespace DynamicBenchmarker {
|
|
35
|
+
/**
|
|
36
|
+
* Properties of the master program.
|
|
37
|
+
*/
|
|
38
|
+
interface IMasterProps {
|
|
39
|
+
/**
|
|
40
|
+
* Total count of the requests.
|
|
41
|
+
*/
|
|
42
|
+
count: number;
|
|
43
|
+
/**
|
|
44
|
+
* Number of threads.
|
|
45
|
+
*
|
|
46
|
+
* The number of threads to be executed as parallel servant.
|
|
47
|
+
*/
|
|
48
|
+
threads: number;
|
|
49
|
+
/**
|
|
50
|
+
* Number of simultaneous requests.
|
|
51
|
+
*
|
|
52
|
+
* The number of requests to be executed simultaneously.
|
|
53
|
+
*
|
|
54
|
+
* This property value would be divided by the {@link threads} in the servants.
|
|
55
|
+
*/
|
|
56
|
+
simultaneous: number;
|
|
57
|
+
/**
|
|
58
|
+
* Path of the servant program.
|
|
59
|
+
*
|
|
60
|
+
* The path of the servant program executing the
|
|
61
|
+
* {@link DynamicBenchmarker.servant} function.
|
|
62
|
+
*/
|
|
63
|
+
servant: string;
|
|
64
|
+
/**
|
|
65
|
+
* Filter function.
|
|
66
|
+
*
|
|
67
|
+
* The filter function to determine whether to execute the function in
|
|
68
|
+
* the servant or not.
|
|
69
|
+
*
|
|
70
|
+
* @param name Function name
|
|
71
|
+
* @returns Whether to execute the function or not.
|
|
72
|
+
*/
|
|
73
|
+
filter?: (name: string) => boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Progress callback function.
|
|
76
|
+
*
|
|
77
|
+
* @param complete The number of completed requests.
|
|
78
|
+
*/
|
|
79
|
+
progress?: (complete: number) => void;
|
|
80
|
+
/**
|
|
81
|
+
* Standard I/O option.
|
|
82
|
+
*
|
|
83
|
+
* The standard I/O option for the servant programs.
|
|
84
|
+
*/
|
|
85
|
+
stdio?: undefined | "overlapped" | "pipe" | "ignore" | "inherit";
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Properties of the servant progrma.
|
|
89
|
+
*/
|
|
90
|
+
interface IServantProps<Parameters extends any[]> {
|
|
91
|
+
/**
|
|
92
|
+
* Default connection.
|
|
93
|
+
*
|
|
94
|
+
* Default connection to be used in the servant.
|
|
95
|
+
*/
|
|
96
|
+
connection: IConnection;
|
|
97
|
+
/**
|
|
98
|
+
* Location of the benchmark functions.
|
|
99
|
+
*/
|
|
100
|
+
location: string;
|
|
101
|
+
/**
|
|
102
|
+
* Prefix of the benchmark functions.
|
|
103
|
+
*
|
|
104
|
+
* Every prefixed function will be executed in the servant.
|
|
105
|
+
*
|
|
106
|
+
* In other words, if a function name doesn't start with the prefix,
|
|
107
|
+
* then it would never be executed.
|
|
108
|
+
*/
|
|
109
|
+
prefix: string;
|
|
110
|
+
/**
|
|
111
|
+
* Get parameters of a function.
|
|
112
|
+
*
|
|
113
|
+
* When composing the parameters, never forget to copy the
|
|
114
|
+
* {@link IConnection.logger} property of default connection to the
|
|
115
|
+
* returning parameters.
|
|
116
|
+
*
|
|
117
|
+
* @param connection Default connection instance
|
|
118
|
+
* @param name Function name
|
|
119
|
+
*/
|
|
120
|
+
parameters: (connection: IConnection, name: string) => Parameters;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Benchmark report.
|
|
124
|
+
*/
|
|
125
|
+
interface IReport {
|
|
126
|
+
count: number;
|
|
127
|
+
threads: number;
|
|
128
|
+
simultaneous: number;
|
|
129
|
+
started_at: string;
|
|
130
|
+
completed_at: string;
|
|
131
|
+
statistics: IReport.IStatistics;
|
|
132
|
+
endpoints: Array<IReport.IEndpoint & IReport.IStatistics>;
|
|
133
|
+
}
|
|
134
|
+
namespace IReport {
|
|
135
|
+
interface IEndpoint {
|
|
136
|
+
method: string;
|
|
137
|
+
path: string;
|
|
138
|
+
}
|
|
139
|
+
interface IStatistics {
|
|
140
|
+
count: number;
|
|
141
|
+
success: number;
|
|
142
|
+
mean: number | null;
|
|
143
|
+
stdev: number | null;
|
|
144
|
+
minimum: number | null;
|
|
145
|
+
maximum: number | null;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Master program.
|
|
150
|
+
*
|
|
151
|
+
* Creates a master program that executing the servant programs in parallel.
|
|
152
|
+
*
|
|
153
|
+
* Note that, {@link IMasterProps.servant} property must be the path of
|
|
154
|
+
* the servant program executing the {@link servant} function.
|
|
155
|
+
*
|
|
156
|
+
* @param props Properties of the master program
|
|
157
|
+
* @returns Benchmark report
|
|
158
|
+
*/
|
|
159
|
+
const master: (props: IMasterProps) => Promise<IReport>;
|
|
160
|
+
/**
|
|
161
|
+
* Create a servant program.
|
|
162
|
+
*
|
|
163
|
+
* Creates a servant program executing the prefixed functions in parallel.
|
|
164
|
+
*
|
|
165
|
+
* @param props Properties of the servant program
|
|
166
|
+
* @returns Servant program as a worker server
|
|
167
|
+
*/
|
|
168
|
+
const servant: <Parameters extends any[]>(props: IServantProps<Parameters>) => Promise<WorkerServer<null, IBenchmarkServant, IBenchmarkMaster>>;
|
|
169
|
+
/**
|
|
170
|
+
* Convert the benchmark report to markdown content.
|
|
171
|
+
*
|
|
172
|
+
* @param report Benchmark report
|
|
173
|
+
* @returns Markdown content
|
|
174
|
+
*/
|
|
175
|
+
const markdown: (report: DynamicBenchmarker.IReport) => string;
|
|
176
|
+
}
|