Upload performance benchmarking
Formidable uses two benchmark paths to measure upload speed. A parser benchmark measures multipart parsing in isolation. An end-to-end workload sends repeated HTTP uploads to a local server so changes can be compared against request handling, file writes, and response completion.
Benchmark scope
The benchmark set separates fast parser work from the full upload path. This distinction helps an engineer tell whether a change affects multipart parsing or the wider server and storage flow.
| Benchmark | Main measure | Included work |
|---|---|---|
| Parser benchmark | Multipart data rate in MB/sec | Synthetic multipart buffer creation and MultipartParser event processing |
| End-to-end benchmark | Requests/sec, latency, and network throughput | HTTP request handling, Formidable parsing, upload-file writes, and JSON responses |
Parser benchmark
The parser benchmark in benchmark/index.js creates a synthetic 1 GB multipart body with one field. It sends that body directly to MultipartParser, measures elapsed time, and reports the resulting MB/sec rate. It also checks that the parser emits the expected part, header, data, and end events, so a speed result is not accepted when the basic parse sequence is wrong.
References: benchmark/index.js• L1-32 benchmark/index.js• L34-57
End-to-end benchmark
The end-to-end path starts a local HTTP server and sends a fixed request workload to its upload endpoint. The server passes each request to Formidable, stores uploaded data under benchmark/testuploads, and returns the parsed fields and files as JSON. The workload tool then reports request rate, latency, HTTP status counts, and throughput.
References: benchmark/server.js• L3-5 benchmark/server.js• L7-29 package.json• L52-54
End-to-end workload
The workload uses a stable local route and a repeatable body file. It is intended to show the cost of the complete upload path rather than only the multipart parser.
Benchmark server
benchmark/server.js is the small server used by the end-to-end run. For POST /api/upload, it creates a Formidable form with a benchmark upload directory and preserved file extensions. A parse error becomes an HTTP error response. A successful parse becomes a JSON response containing the fields and files produced by Formidable.
This server uses the same native Node HTTP request shape that an application can use when integrating Formidable. The broader request connection patterns are described in Server integration patterns. The multipart processing behind a multipart request is described in Multipart upload handling.
References: benchmark/server.js• L7-29 src/index.js• L1-27
Workload sequence
The following sequence shows how the end-to-end run turns a request body into a measured result.
sequenceDiagram
participant Runner as Bombardier
participant Server as Benchmark server
participant Form as Formidable
participant Disk as benchmark/testuploads
Runner->>Server: POST /api/upload with README.md body
Server->>Form: Parse the HTTP request
Form->>Disk: Write uploaded data
Form-->>Server: Fields and files
Server-->>Runner: JSON response
Runner-->>Runner: Record rate, latency, status, throughput
The normal command starts the server with pnpm run bench2prep. A separate command runs Bombardier for 10 seconds with 100 connections and uses README.md as the request body: pnpm run bench2. The same two-step sequence is recorded in benchmark/e2e.txt.
References: package.json• L52-54 benchmark/e2e.txt• L1-2 benchmark/server.js• L13-27
Result records
Benchmark results are point-in-time records, not fixed product limits. CPU, disk speed, Node.js version, request tool, and connection load can change the result, so a useful comparison keeps those conditions visible.
Recorded measurements
The checked-in result record shows both benchmark types on an i5-9600k system. The parser runs report 4,132.23 MB/sec on Node 18.0.0 and 3,952.57 MB/sec on Node 19.2.0. The end-to-end run reports 2,824.09 requests/sec on average, 35.51 ms average latency, no 4xx or 5xx responses, and 102.08 MB/sec throughput.
The README also keeps older parser-only results from a Xeon X3440 system. It warns that those results come from an older codebase and that stronger benchmarking may be needed. Use them as historical context rather than as a current target.
References: benchmark/2022-11-30-i5-9600k.txt• L1-30 README.md• L264-296
Comparison basis
For a Formidable change, compare like with like. Keep the request body, run length, connection count, server route, upload directory, and Node.js version unchanged. Record both the parser rate and the end-to-end result when a change can affect both layers.
A parser result can improve while the full upload result does not. This occurs when the main cost is outside parsing, such as file output or request scheduling. The two measurements therefore answer different questions and should not be merged into one score.
References: benchmark/index.js• L5-7 benchmark/index.js• L20-32 package.json• L52-54 benchmark/2022-11-30-i5-9600k.txt• L7-30
Change checklist
When these files or sections are changed, remember to consider these:
- If the upload route or Formidable options change in benchmark/server.js, keep the workload description and stored result conditions aligned with the new path.
- If the request body, duration, or connection count changes in package.json or benchmark/e2e.txt, treat later end-to-end numbers as a new comparison set.
- If the parser input shape or event contract changes in benchmark/index.js, keep its expected event sequence aligned with the parser behavior before comparing speed.
- If the upload output path changes, remove or isolate old files before a run so disk state does not affect the result.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| The benchmark server is not running on port 3000 | The workload cannot connect and produces no upload result | Run bench2prep first and confirm the server reports http://localhost:3000 |
| The workload uses a different body or request shape | The result no longer measures the same upload path | Keep the README.md body, POST method, route, duration, and connection count fixed for comparisons |
| A request parse or file-write error occurs | The run can show failed HTTP responses or understate successful throughput | Check the HTTP status counts and server error output instead of using throughput alone |
| Old files remain in the upload directory | Disk state can influence later runs and confuse the measured cost | Use an isolated or cleaned benchmark/testuploads directory for each comparison set |
| The parser event sequence changes or ends early | The parser speed number is not a valid measure of a complete parse | Keep the event-count assertion in the parser benchmark passing |
Key files
| File | Why to read it |
|---|---|
| benchmark/server.js | Defines the local HTTP upload route and the Formidable-to-disk-to-response path used by the end-to-end benchmark. |
| benchmark/index.js | Defines the isolated multipart workload and its correctness check. |
| package.json | Defines the commands and fixed Bombardier workload settings for both benchmark paths. |
| benchmark/e2e.txt | Shows the short, two-command end-to-end run sequence. |
| benchmark/2022-11-30-i5-9600k.txt | Records example parser and end-to-end measurements with their Node.js versions and run conditions. |
| README.md | Gives historical benchmark context and older parser results. |