pgpool2.git / summary / log / commit / refs

commit    a7174263552cae162d571e0e97387bd541fa2a27
Author:   Tatsuo Ishii <ishii@postgresql.org>
Date:     Thu May 10 02:28:22 2012 +0000

    Fix load balance in Solaris.  If compiled in Solaris, use
    srand()/rand() instead of srandom()/random().  Problem is, random() in
    Solaris does not respect RAND_MAX (it's 2^16-1 in Solaris). So using
    random() in Solaris results in strange load balancing calculation.
    Use srand()/rand() instead although they produce lesser quality random
    numbers. Problem reported at [pgpool-general: 396].


child.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/child.c b/child.c index 203e58000..23df92f33 100644 --- a/child.c +++ b/child.c @@ -141,7 +141,11 @@ void do_child(int unix_fd, int inet_fd) /* initialize random seed */ gettimeofday(&now, &tz); +#if defined(sun) || defined(__sun) + srand((unsigned int) now.tv_usec); +#else srandom((unsigned int) now.tv_usec); +#endif /* initialize system db connection */ init_system_db_connection(); @@ -1907,7 +1911,13 @@ int select_load_balancing_node(void) 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++) { [parent: 5b2cd3338235]