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

fix: new variant hashing #533

Merged
merged 2 commits into from
Oct 30, 2023
Merged

fix: new variant hashing #533

merged 2 commits into from
Oct 30, 2023

Conversation

kwasniew
Copy link
Contributor

@kwasniew kwasniew commented Oct 30, 2023

What

Uses a new seed for ensuring a fair distribution for variants.

Background

After a customer reported that variant distribution seemed skewed we performed some testing and found that since we use the same hash string for both gradual rollout and variant allocation we'd reduced the set of groups we could get to whatever percentage our gradual rollout was set.

Example

Take a gradualRollout of 10%, this will select normalized hashes between 1 and 10, when we then again hash the same string that gave us between 1 and 10, but with modulo 1000 for variants, this will only give us 100 possible groups, instead of the expected 1000.

Fix

Force the normalization to accept a seed, and make sure to use a new seed when normalizing the variant distribution hash.

Worth noting

This will require release of a new major version, since we are changing how hashing works.

@@ -1,5 +1,23 @@
import * as murmurHash3 from 'murmurhash3js';

export default function normalizedValue(id: string, groupId: string, normalizer = 100): number {
return (murmurHash3.x86.hash32(`${groupId}:${id}`) % normalizer) + 1;
function normalizedValue(id: string,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

making this private since I want other code to use strategy or variant specific functions

@coveralls
Copy link

Coverage Status

coverage: 91.45% (-0.03%) from 91.484% when pulling 2eb3b52 on new-variant-hashing into 69516d9 on main.

const STRATEGY_SEED = 0;

export function normalizedStrategyValue(id: string, groupId: string): number {
return normalizedValue(id, groupId, 100, STRATEGY_SEED);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like existing code always assumes 100 for strategies

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we do, because the percentage slider for our gradualRollouts are 0-100 %


export function normalizedVariantValue(id: string,
groupId: string,
normalizer: number): number {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for variants we want to force the normalizer usage by the calling code

return normalizedValue(id, groupId, 100, STRATEGY_SEED);
}

const VARIANT_SEED = 86028157;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I deliberate don't want this to leak out to the calling code

Copy link
Contributor

@chriswk chriswk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

@kwasniew kwasniew merged commit ca52827 into main Oct 30, 2023
4 checks passed
@kwasniew kwasniew deleted the new-variant-hashing branch October 30, 2023 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants