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

Priority balancing doesn't work as expected #2209

Closed
lambdamedia opened this issue Oct 30, 2022 · 4 comments · Fixed by #2840
Closed

Priority balancing doesn't work as expected #2209

lambdamedia opened this issue Oct 30, 2022 · 4 comments · Fixed by #2840
Labels

Comments

@lambdamedia
Copy link

lambdamedia commented Oct 30, 2022

set of 1, 50, 100 is balancing tiny, 25% and 50% accordingly

In comment of priority it says

"This priority will determine the likelihood of this IP address being selected for use when sending a message. The higher the number the more likely the IP is to be chosen. By defalt, the priority is set to the maximum value of 100.
This can be used to warm up new IP addresses by adding them with a low priority.
To give an indication of how this works, if you have three IPs with 1, 50 and 100 as their priorities, and you send 100,000 emails, the priority 1 address will receive
a tiny percentage, the priority 50 will receive roughly 25% and the priority 100 will receive roughly 75%.

To Reproduce

  1. Set 3 IPs
  2. Set up distribution 1,50,100

Expected behaviour

1/151 goes to 1
50/151 goes to 50
100/151 goes to 100

It's expected more like 33/66% for 50/100 weights

How feature can be used as expected? Is that a bug or performance efficient feature?

How to calculate proper rate of distribution?

Thank you!

Link to code:

order(Arel.sql("RAND() * priority DESC")).first

@willpower232
Copy link
Collaborator

I don't think that this implementation of RAND would actually achieve a specific amount of traffic going to a specific IP address, definitely not over a small sample size of 150 messages.

Stack Overflow seems to suggest that guaranteeing percentages of messages going to certain IP addresses would require something a little more complicated https://stackoverflow.com/questions/61285226/selecting-rows-by-percentage-of-chance

I'm definitely not a statistician so I don't know what I'm talking about at all but if you're not sending many thousands of messages then I'd say your priority numbers should be closer together (i.e. don't use 1, 50, 100, use 50, 100, 100) so that your newer IP address actually stands a chance of being used.

@lambdamedia
Copy link
Author

lambdamedia commented Oct 31, 2022

There is a specific ratio we need to achieve on specific pool of IPs.
With current implementation is impossible to do.

Let's say we would like to allocate 10% on IP A, 25% on IP B, 40% on IP C and 25 % IP D.
What ratio needs to be set?

There is no such a way besides jumping into statistic and getting right ratios which is not
10, 25, 40, 25 for sure.

In my opinion implementation of load balancing is not correct.
For example in Nginx where you set weight for load balancing - it does process close to weights were set.

https://github.com/nginx/nginx/blob/a64190933e06758d50eea926e6a55974645096fd/src/stream/ngx_stream_upstream_round_robin.c#L582

@willpower232
Copy link
Collaborator

As I said, I don't think you can achieve specific ratios but as those numbers are relatively close together, it might get pretty close in the current implementation.

There would need to be a bit of a code change to achieve specific ratios and then there would probably have to be some kind of limit on the ratio values entered, don't want someone entering 10000 and crashing Postal whilst it tries to figure out all the possible permutations 😅

@catphish
Copy link
Contributor

catphish commented Nov 9, 2022

To give an indication of how this works, if you have three IPs with 1, 50 and 100 as their priorities, and you send 100,000 emails, the priority 1 address will receive a tiny percentage, the priority 50 will receive roughly 25% and the priority 100 will receive roughly 75%.

This documentation is wrong. Your description is correct.

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

Successfully merging a pull request may close this issue.

4 participants