yoyall 5 Posted ... Let me preface this by apologising if this has already been covered elsewhere. I did do a quick search to see if it had. What I'm curious about is understanding the "latency" and "speed" scoring rules better. Am I correct in that the "latency" scoring rule is simply finding the lowest ping time between me and the vpn server? But then, what about "speed"? Is it the vpn server that users are achieving the highest speed? Or is it more smarter than that - in that it's the server on which I'll likely achieve the highest speed? I suppose what I'm getting at is that wouldn't it nearly always be the case that you'll achieve the highest speed with the server that also scores the best in terms of latency? Or put another way, wouldn't you always be better off using the "latency" score? Thanks in advance for any assistance. Cheers, Jules Quote Share this post Link to post
OpenSourcerer 1441 Posted ... (edited) Let's talk code. public int Score() { lock (Warnings) { if (HasWarningsErrors()) return 99998; else if (Warnings.Count > 0) return 99997; else if (Ping == -1) return 99995; else { string scoreType = Engine.Instance.Options.GetLower("servers.scoretype"); double x = Users; double x2 = UsersPerc(); double PenalityB = Penality * Convert.ToDouble(Provider.GetKeyValue("penality_factor", "1000")); double PingB = Ping * Convert.ToDouble(Provider.GetKeyValue("ping_factor", "1")); double LoadB = LoadPerc() * Convert.ToDouble(Provider.GetKeyValue("load_factor", "1")); double UsersB = UsersPerc() * Convert.ToDouble(Provider.GetKeyValue("users_factor", "1")); double ScoreB = ScoreBase; if (scoreType == "speed") { ScoreB = ScoreB / Convert.ToDouble(Provider.GetKeyValue("speed_factor", "1")); LoadB = LoadB / Convert.ToDouble(Provider.GetKeyValue("speed_load_factor", "1")); // 2.18.7 UsersB = UsersB / Convert.ToDouble(Provider.GetKeyValue("speed_users_factor", "1")); // 2.18.7 } else if (scoreType == "latency") { ScoreB = ScoreB / Convert.ToDouble(Provider.GetKeyValue("latency_factor", "500")); LoadB = LoadB / Convert.ToDouble(Provider.GetKeyValue("latency_load_factor", "10")); // 2.18.7 UsersB = UsersB / Convert.ToDouble(Provider.GetKeyValue("latency_users_factor", "10")); // 2.18.7 } return Conversions.ToInt32(PenalityB + PingB + LoadB + ScoreB + UsersB); } } } The score is the sum of multiple values multiplied by different factors: "Penality" (penalty?), ping, load percentage, users percentage and a "ScoreBase". The factors are 1000, 1, 1, 1 and 1 initially. It makes sense that for each server the raw values are taken from some other location in the code base: Ping from the results of ping, Load and Users from the current server status values. "Penality" is a little unclear to me. If there is a note on a server like "Line problems" or "High packet loss", the value is set to an astronomically high value, here 99998 for errors, 99997 for warnings and 99995 if ping didn't return usable results, so the score will be 0 stars. Let's calculate both on the basis of two servers: A: latency 50, load 20%, 50 clients. B: latency 10, load 50%, 80 clients. For the Speed metric values are divided by preset factors, the results added: Penality (not sure about the values here, let's say, it's all roses now) / 1000 = 0.0 Ping: 50 / 1 = 50 LoadPerc: 20 / 1 = 20 ScoreBase (initially 0, unsure where set) / 1 = 0 UsersPerc: 50 / 1 = 50 0+50+20+0+50 = 120 Server B: Penality: 0 / 1000 = 0 Ping: 10 / 1 = 10 LoadPerc: 50 / 1 = 50 ScoreBase: 0 / 1 = 0 UsersPerc: 80 / 1 = 80 0+10+50+0+80=140. Server A is better, despite much higher latency. For the latency metric, server A: Penality: 0 / 1000 = 0 Ping: 50 / 1 = 50 LoadPerc: 20 / 10 = 2 ScoreBase: 0 / 500 = 0 UsersPerc: 50 / 10 = 5 Server A: 0 + 50 + 2 + 0 + 5 = 57 Server B: 0 + 10 + 5 + 0 + 8 = 23 Server B is better, despite much higher activity. All factors are decreased in importance in the Latency metric, so the ping value can be used as is in the formula. But all factors from Speed are still used. That's what I take away from reading that bit of code. Hope that helps you a little. Edited ... by OpenSourcerer Various crimes against basic calculus corrected Quote Hide OpenSourcerer's signature Hide all signatures NOT AN AIRVPN TEAM MEMBER. USE TICKETS FOR PROFESSIONAL SUPPORT. LZ1's New User Guide to AirVPN « Plenty of stuff for advanced users, too! Want to contact me directly? All relevant methods are on my About me page. Share this post Link to post
yoyall 5 Posted ... Wow! That was brilliant and just the understanding that I was looking for. I really appreciate you taking the time to illustrate the rules with examples. It now makes perfect sense. Again, thanks very much for providing such a detailed and informative explanation. 🙏👍👍 Quote Share this post Link to post
OpenSourcerer 1441 Posted ... If you want to know how the stars are calculated, the code is directly beneath the Score() function: public float ScorePerc() { float scoreF = (Score() - 70); scoreF /= 70; float part = 1; if (scoreF > 5) part = 0; else if (scoreF > 1) part /= scoreF; return part; } Here the previous examples from the Score metric are a little bad. Server A was 120: 120 - 70 = 50 50 divided by 70 = 5/7 = ~0,714. It's not bigger than 5 or 1, so function returns 1. Server B was 140: - 70 = 70 divided by 70 = 1 Not bigger than 1, function returns 1. Both servers get 5 stars in the process. If that operation returns something bigger than 1, 1 is divided by whatever it returns, leading to a result between 0 and 1. This is important for the stars calculation. In another part of the code, it's translated into stars: else if (tableColumn.Identifier == "Score") { int p = Convert.ToInt32(5 * s.ScorePerc()); return NSImage.ImageNamed("stars_" + p.ToString() + ".png"); } The return value of ScorePerc() is multiplied with 5. If it's 1, it's 5 stars, simple. But you may notice now that a decimal return value from ScorePerc() causes the calculation to be less than 5. So if a server gets 280 as a result of very high latency and much activity, the result would be: 280-70 = 210 / 70 = 3 1/3 = 0,333 5*0,333 = 1,666, converted to integer, so probably implicitly rounded: 2 stars This is fed to a function showing an image with the name stars_2.png. Oh, and in case of an error/warning/bad ping result: 99995-70 = 99925 /70 = 1427.5 1/1427 = 0.0007 * 5 = 0.0035, that's a stars_0.png image. Quote Hide OpenSourcerer's signature Hide all signatures NOT AN AIRVPN TEAM MEMBER. USE TICKETS FOR PROFESSIONAL SUPPORT. LZ1's New User Guide to AirVPN « Plenty of stuff for advanced users, too! Want to contact me directly? All relevant methods are on my About me page. Share this post Link to post
yoyall 5 Posted ... Thanks again for this - really appreciate all the information and explanations - very helpful! 👍👍 Quote Share this post Link to post