Last active
January 1, 2016 10:19
-
-
Save mender/8130951 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Select load balancing node | |
| */ | |
| int select_load_balancing_node(void) | |
| { | |
| int selected_slot; | |
| double total_weight,r; | |
| int i; | |
| /* choose a backend in random manner with weight */ | |
| selected_slot = MASTER_NODE_ID; | |
| total_weight = 0.0; | |
| for (i=0;i<NUM_BACKENDS;i++) | |
| { | |
| if (VALID_BACKEND(i)) | |
| { | |
| total_weight += BACKEND_INFO(i).backend_weight; | |
| } | |
| } | |
| #if defined(sun) || defined(__sun) | |
| r = (((double)rand())/RAND_MAX) * total_weight; | |
| #else | |
| r = (((double)random())/RAND_MAX) * total_weight; | |
| #endif | |
| total_weight = 0.0; | |
| for (i=0;i<NUM_BACKENDS;i++) | |
| { | |
| if (VALID_BACKEND(i) && BACKEND_INFO(i).backend_weight > 0.0) | |
| { | |
| if(r >= total_weight) | |
| selected_slot = i; | |
| else | |
| break; | |
| total_weight += BACKEND_INFO(i).backend_weight; | |
| } | |
| } | |
| pool_debug("select_load_balancing_node: selected backend id is %d", selected_slot); | |
| return selected_slot; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment