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

perf: pregenerate timeWindow string when possible and use noop as default function #364

Merged
merged 8 commits into from
Feb 24, 2024

Conversation

gurgunday
Copy link
Member

@gurgunday gurgunday commented Feb 24, 2024

We shouldn't keep recreating the string if it's static, it might become a problem under an attack

Note: This was already the case, but it got removed in #357

@gurgunday
Copy link
Member Author

Not seeing a real benefit in benchmarks, so will close this one

@gurgunday gurgunday closed this Feb 24, 2024
@gurgunday
Copy link
Member Author

Ok, now it's better on my end:

NEW:

Running 10s test @ http://127.0.0.1:3000/
10 connections


┌─────────┬──────┬──────┬───────┬──────┬─────────┬─────────┬───────┐
│ Stat    │ 2.5% │ 50%  │ 97.5% │ 99%  │ Avg     │ Stdev   │ Max   │
├─────────┼──────┼──────┼───────┼──────┼─────────┼─────────┼───────┤
│ Latency │ 0 ms │ 0 ms │ 0 ms  │ 0 ms │ 0.01 ms │ 0.06 ms │ 14 ms │
└─────────┴──────┴──────┴───────┴──────┴─────────┴─────────┴───────┘
┌───────────┬─────────┬─────────┬─────────┬─────────┬──────────┬──────────┬─────────┐
│ Stat      │ 1%      │ 2.5%    │ 50%     │ 97.5%   │ Avg      │ Stdev    │ Min     │
├───────────┼─────────┼─────────┼─────────┼─────────┼──────────┼──────────┼─────────┤
│ Req/Sec   │ 48,991  │ 48,991  │ 52,671  │ 53,823  │ 52,365.1 │ 1,201.95 │ 48,981  │
├───────────┼─────────┼─────────┼─────────┼─────────┼──────────┼──────────┼─────────┤
│ Bytes/Sec │ 17.2 MB │ 17.2 MB │ 19.7 MB │ 20.2 MB │ 19.5 MB  │ 770 kB   │ 17.2 MB │
└───────────┴─────────┴─────────┴─────────┴─────────┴──────────┴──────────┴─────────┘

Req/Bytes counts sampled once per second.
# of samples: 11

10000 2xx responses, 565963 non 2xx responses
576k requests in 11.01s, 215 MB read

OLD:

Running 10s test @ http://127.0.0.1:3000/
10 connections


┌─────────┬──────┬──────┬───────┬──────┬─────────┬─────────┬───────┐
│ Stat    │ 2.5% │ 50%  │ 97.5% │ 99%  │ Avg     │ Stdev   │ Max   │
├─────────┼──────┼──────┼───────┼──────┼─────────┼─────────┼───────┤
│ Latency │ 0 ms │ 0 ms │ 0 ms  │ 0 ms │ 0.01 ms │ 0.06 ms │ 14 ms │
└─────────┴──────┴──────┴───────┴──────┴─────────┴─────────┴───────┘
┌───────────┬─────────┬─────────┬─────────┬─────────┬──────────┬────────┬─────────┐
│ Stat      │ 1%      │ 2.5%    │ 50%     │ 97.5%   │ Avg      │ Stdev  │ Min     │
├───────────┼─────────┼─────────┼─────────┼─────────┼──────────┼────────┼─────────┤
│ Req/Sec   │ 49,375  │ 49,375  │ 51,391  │ 52,383  │ 51,308.8 │ 978.75 │ 49,373  │
├───────────┼─────────┼─────────┼─────────┼─────────┼──────────┼────────┼─────────┤
│ Bytes/Sec │ 17.5 MB │ 17.5 MB │ 19.3 MB │ 19.6 MB │ 19.1 MB  │ 618 kB │ 17.5 MB │
└───────────┴─────────┴─────────┴─────────┴─────────┴──────────┴────────┴─────────┘

Req/Bytes counts sampled once per second.
# of samples: 10

10000 2xx responses, 503109 non 2xx responses
513k requests in 10.01s, 191 MB read

@gurgunday gurgunday reopened this Feb 24, 2024
@gurgunday gurgunday changed the title perf: pregenerate timeWindow string when possible perf: pregenerate timeWindow string when possible and use noop as default function Feb 24, 2024
@gurgunday
Copy link
Member Author

Uzlopak was right, noop is faster than ?.

@gurgunday gurgunday merged commit aa83957 into fastify:next Feb 24, 2024
13 checks passed
@gurgunday gurgunday deleted the string branch February 24, 2024 15:07
jsumners added a commit that referenced this pull request Jul 10, 2024
* Updating for v5 (#338)

* ci: add node 21 to test matrix and remove node 14 and 16

* package.json update for v5

* merge main to next (#348)

* Update README.md to reflect #307 (#342)

* Redis should work with ban (#336)

* Redis should work with ban

* fix ttl

* simplify

* format

* remove warning

* move property

* add test

* fix test

* fix test

* fix test

* still fix the same test

* make it non-breaking

* make it non-breaking

* make it non-breaking

* make it non-breaking

* perf: add ban back

* Bumped v8.1.0

Signed-off-by: Matteo Collina <[email protected]>

* Bumped v9.0.0

Signed-off-by: Matteo Collina <[email protected]>

* Fix in-memory cache bug when there is only one entry (#345)

* Bumped v9.0.1

---------

Signed-off-by: Matteo Collina <[email protected]>
Co-authored-by: Trevor Lund <[email protected]>
Co-authored-by: Matteo Collina <[email protected]>
Co-authored-by: Igor Savin <[email protected]>

* Revert "merge main to next (#348)"

This reverts commit 5446122.

* revert workflow update as its causing issues (#350)

* revert: handle ban in store (#347)

* remove ban handling from store

* don't use negation

* add undef

* don't pass ban to promis

* fix accidental explicit checks

* fix accidental line change

* inline ban

* Workflow v4 (#354)

* refactor: make RedisStore default key a default parameter (#356)

* refactor redis parameters and throw if no instance was provided

* revert error

* Add function support for timeWindow (#357)

* feat: dynamic time window support

* fix: proper usage of timeWindowString

---------

Co-authored-by: lukas <[email protected]>

* update docs (#360)

* fix: remove unnecessary parameter timeWindow (#363)

* refactor: consistent option handling (#365)

* small refactor in option handling

* simplify

* simplify

* perf: pregenerate `timeWindow` string when possible and use `noop` as default function (#364)

* pregenerate timeWindowString if possible

* simplify

* simplify

* noop

* simplify

* simple-example

* rename

* update for v5 (#370)

* update for v5

* update for v5

* update for v5

* update for v5

* update for v5

* update for v5

* update for v5

* update for v5

* update for v5

* update for v5

* update for v5

* update for v5

* update for v5

* update for v5

* update fastify deps

---------

Signed-off-by: Matteo Collina <[email protected]>
Co-authored-by: Eliphaz Bouye <[email protected]>
Co-authored-by: Gürgün Dayıoğlu <[email protected]>
Co-authored-by: Trevor Lund <[email protected]>
Co-authored-by: Matteo Collina <[email protected]>
Co-authored-by: Igor Savin <[email protected]>
Co-authored-by: lukas <[email protected]>
Co-authored-by: lukas <[email protected]>
Co-authored-by: Gürgün Dayıoğlu <[email protected]>
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

Successfully merging this pull request may close these issues.

2 participants