forked from denoland/deno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(ext/fetch): consume body using ops (denoland#16038)
This commit adds a fast path to `Request` and `Response` that make consuming request bodies much faster when using `Body#text`, `Body#arrayBuffer`, and `Body#blob`, if the body is a FastStream. Because the response bodies for `fetch` are FastStream, this speeds up consuming `fetch` response bodies significantly.
- Loading branch information
Showing
16 changed files
with
291 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. | ||
|
||
const addr = Deno.args[0] || "127.0.0.1:4500"; | ||
const [hostname, port] = addr.split(":"); | ||
const { serve } = Deno; | ||
|
||
async function handler(request) { | ||
try { | ||
const buffer = await request.arrayBuffer(); | ||
return new Response(buffer.byteLength); | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
} | ||
|
||
serve(handler, { hostname, port }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
wrk.method = "POST" | ||
wrk.headers["Content-Type"] = "application/octet-stream" | ||
|
||
file = io.open("./cli/bench/testdata/128k.bin", "rb") | ||
wrk.body = file:read("*a") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. | ||
|
||
const addr = Deno.args[0] || "127.0.0.1:4500"; | ||
const [hostname, port] = addr.split(":"); | ||
const listener = Deno.listen({ hostname, port: Number(port) }); | ||
console.log("Server listening on", addr); | ||
|
||
for await (const conn of listener) { | ||
(async () => { | ||
const requests = Deno.serveHttp(conn); | ||
for await (const { respondWith, request } of requests) { | ||
if (request.method == "POST") { | ||
const buffer = await request.arrayBuffer(); | ||
respondWith(new Response(buffer.byteLength)) | ||
.catch((e) => console.log(e)); | ||
} | ||
} | ||
})(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
wrk.method = "POST" | ||
wrk.headers["Content-Type"] = "application/octet-stream" | ||
|
||
file = io.open("./cli/bench/testdata/128k.bin", "rb") | ||
wrk.body = file:read("*a") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. | ||
const http = require("http"); | ||
const port = process.argv[2] || "4544"; | ||
console.log("port", port); | ||
http | ||
.Server((req, res) => { | ||
if (req.method == "POST") { | ||
let chunks = []; | ||
req.on("data", function (data) { | ||
chunks.push(data); | ||
}); | ||
req.on("end", function () { | ||
const buffer = Buffer.concat(chunks); | ||
res.end(buffer.byteLength.toString()); | ||
}); | ||
} | ||
}) | ||
.listen(port); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
wrk.method = "POST" | ||
wrk.headers["Content-Type"] = "application/octet-stream" | ||
|
||
file = io.open("./cli/bench/testdata/128k.bin", "rb") | ||
wrk.body = file:read("*a") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.