express-ntlm
express-ntlm copied to clipboard
Slow processing time for requests with files
Hi,
I have/upload
endpoint using busboy library.
the idea is to use node-streams in order to process the file fast as possible (and stream it to another service)
in the very beginning of my function, I print some msg (ie: inside upload
)
if i'm using the ntlm()
middleware - the output is being delayed. and for big files - it can take a couple of minutes.
I guess it related to the handshake mechanisem - which involes sending the request back and forth before actually pass the middleware.
without ntlm()
2ms from the request recieved until the upload function init msg
with ntlm()
~25 seconds for the same process
I wonder if this something we can improve? (ie ignoring the form-data body or something?)
import express from "express";
import ntlm from "express-ntlm";
import cors from "cors";
import busboy from "connect-busboy";
const app = express();
const port = process.env.PORT || 3000;
const logger = function (msg) {
const handler = (req, res, next) => {
console.log(getTime(), req.method, req.path, msg);
next();
};
return handler;
};
app.use(cors({ credentials: true, origin: "http://localhost:4200" }));
app.use(express.json());
app.use(logger("BEFORE NTLM"));
app.use(
ntlm({
debug: function () {
var args = Array.prototype.slice.apply(arguments);
console.log.apply(null, args);
},
})
);
app.post("/upload", busboy({ immediate: false }), (req, res) => {
console.log(getTime(), "INSIDE UPLOAD METHOD");
res.send({ result: 'done'})
});
app.listen(port, () => {
console.log(`⚡️[server]: Server is running at http://localhost:${port}`);
});
const getTime = () => new Date().toISOString().split("T")[1].substring(0, 12);