Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fastify etag bringing QPS down for paths where dummy etags have been added #106

Open
2 tasks done
kp198 opened this issue Jun 20, 2023 · 6 comments
Open
2 tasks done

Comments

@kp198
Copy link

kp198 commented Jun 20, 2023

Prerequisites

  • I have written a descriptive issue title
  • 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

@mcollina
Copy link
Member

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.

@kp198
Copy link
Author

kp198 commented Jun 20, 2023

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.

@mcollina
Copy link
Member

You are bypassing Fastify headers logic by using the raw object.

@kp198
Copy link
Author

kp198 commented Jun 27, 2023

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

@Uzlopak
Copy link
Contributor

Uzlopak commented Jun 29, 2023

What do you get as etag value if you do a console.log(etag) after

let etag = reply.getHeader('etag')

?

@kp198
Copy link
Author

kp198 commented Jun 30, 2023

I get the 'etag' here @Uzlopak

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants