Fastify etag bringing QPS down for paths where dummy etags have been added
Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
Fastify version
4.15.0
Plugin version
4.2.0
Node.js version
16.5.1
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
12.6.5
Description
I used the fastify etag plugin and for the url paths where I did not require etag I added a dummy etag but the QPS for both the paths decreased significantly after adding the plugin
I also tried generating etag myself and this seemed to be give me better QPS. Any reasons for this strange behaviour or is this expected?
const hash = crypto.createHash('sha256');
const stringDoc: string = JSON.stringify(documentData);
etag = hash.update(stringDoc).digest('hex');
Steps to Reproduce
Add reply.raw.setHeader(etag, 'dummyetag'); to one path's reply and check if there is a drop in QPS
Expected Behavior
The QPS should not decrease for paths that already have etag headers
Thanks for reporting!
Can you provide steps to reproduce? We often need a reproducible example, e.g. some code that allows someone else to recreate your problem by just copying and pasting it. If it involves more than a couple of different file, create a new repository on GitHub and add a link to that.
server.get('/dummyetag', async (request, reply) => {
reply.raw.setHeader('etag','etag')
return reply.code(200).send({test: 'Dummy etag'});
});
server.get('/fastifyetag', async (request, reply) => {
return reply.code(200).send({test: 'Fastify etag'});
});
So let's say there are 2 paths like this, both give me the same QPS. Although this is not the exact data. in my use case around 100kb of data is used for generating the etag.
You are bypassing Fastify headers logic by using the raw object.
so shouldn't the QPS of the /dummyetag path be lesser since etag generation is not happening I notice the same QPS for both paths which is weird
What do you get as etag value if you do a console.log(etag) after https://github.com/fastify/fastify-etag/blob/ddefbef401108093e3dde303f548f1ee4b02a733/index.js#L36 ?
I get the 'etag' here @Uzlopak