It's working.<div><br clear="all">Regards,<br>Aravinth<br>
<br><br><div class="gmail_quote">On Wed, May 9, 2012 at 5:26 PM, Tatsuo Ishii <span dir="ltr"><<a href="mailto:ishii@postgresql.org" target="_blank">ishii@postgresql.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Thanks for the hint. Attached is a patch trying to fix the<br>
problem. Can you please try it?<br>
<div class="HOEnZb"><div class="h5">--<br>
Tatsuo Ishii<br>
SRA OSS, Inc. Japan<br>
English: <a href="http://www.sraoss.co.jp/index_en.php" target="_blank">http://www.sraoss.co.jp/index_en.php</a><br>
Japanese: <a href="http://www.sraoss.co.jp" target="_blank">http://www.sraoss.co.jp</a><br>
<br>
> Yes the issue is with random() function.<br>
><br>
> Looks like I have solved the problem by using rand.<br>
><br>
> Regards,<br>
> Aravinth<br>
><br>
><br>
> On Wed, May 9, 2012 at 4:02 PM, Tatsuo Ishii <<a href="mailto:ishii@postgresql.org">ishii@postgresql.org</a>> wrote:<br>
><br>
>> Thanks. Apparently random() of Solaris could return value beyond<br>
>> RAND_MAX! It's easy to fix the problem, but I would like to do it with<br>
>> respcet to portability. Any idea?<br>
>> --<br>
>> Tatsuo Ishii<br>
>> SRA OSS, Inc. Japan<br>
>> English: <a href="http://www.sraoss.co.jp/index_en.php" target="_blank">http://www.sraoss.co.jp/index_en.php</a><br>
>> Japanese: <a href="http://www.sraoss.co.jp" target="_blank">http://www.sraoss.co.jp</a><br>
>><br>
>> >>From Solaris 10 (x86) man page:<br>
>> ><br>
>> ><br>
>> > SYNOPSIS<br>
>> >      #include <stdlib.h><br>
>> ><br>
>> >      long random(void);<br>
>> ><br>
>> >      void srandom(unsigned int seed);<br>
>> ><br>
>> >      char  *initstate(unsigned  int  seed,  char  *state,  size_t<br>
>> >      size);<br>
>> ><br>
>> >      char *setstate(const char *state);<br>
>> ><br>
>> > DESCRIPTION<br>
>> >      The random() function uses  a  nonlinear  additive  feedback<br>
>> >      random-number generator employing a default state array size<br>
>> >      of 31  long  integers  to  return  successive  pseudo-random<br>
>> >      numbers  in the range from 0 to 2**31 -1. The period of this<br>
>> >      random-number generator is approximately 16 x (2 **31   -1).<br>
>> >      The  size  of  the  state array determines the period of the<br>
>> >      random-number generator. Increasing  the  state  array  size<br>
>> >      increases the period.<br>
>> ><br>
>> >      The srandom() function initializes the current  state  array<br>
>> >      using the value of seed.<br>
>> ><br>
>> ><br>
>> > (...)<br>
>> ><br>
>> ><br>
>> ><br>
>> > Regards,<br>
>> > Rafal<br>
>> ><br>
>> ><br>
>> ><br>
>> > -----Original Message-----<br>
>> > From: <a href="mailto:pgpool-general-bounces@pgpool.net">pgpool-general-bounces@pgpool.net</a> [mailto:<br>
>> <a href="mailto:pgpool-general-bounces@pgpool.net">pgpool-general-bounces@pgpool.net</a>] On Behalf Of Tatsuo Ishii<br>
>> > Sent: Wednesday, May 09, 2012 11:44 AM<br>
>> > To: <a href="mailto:caravinth@gmail.com">caravinth@gmail.com</a><br>
>> > Cc: <a href="mailto:pgpool-general@pgpool.net">pgpool-general@pgpool.net</a><br>
>> > Subject: [pgpool-general: 431] Re: strange load balancing issue in<br>
>> Solaris<br>
>> ><br>
>> > Thanks.<br>
>> ><br>
>> > 2012-05-09 14:31:48 LOG:   pid 22459: r: 268356063.000000 total_weight:<br>
>> 32767.000000<br>
>> ><br>
>> > This is really weird. Here pgpool caculate this:<br>
>> ><br>
>> >       r = (((double)random())/RAND_MAX) * total_weight;<br>
>> ><br>
>> > Total weight is same as RAND_MAX.  It seems your random() returns<br>
>> > bigger than RAND_MAX, which does not make sense because man page of<br>
>> > random(3) on my Linux says:<br>
>> ><br>
>> >          The random() function uses a non-linear additive feedback<br>
>> random number<br>
>> >        generator  employing a default table of size 31 long integers to<br>
>> return<br>
>> >        successive pseudo-random numbers in the range from 0 to RAND_MAX.<br>
>>   The<br>
>> >        period  of  this  random  number generator is very large,<br>
>> approximately<br>
>> >        16 * ((2^31) - 1).<br>
>> ><br>
>> > What does your man page for random() say on your system?<br>
>> > --<br>
>> > Tatsuo Ishii<br>
>> > SRA OSS, Inc. Japan<br>
>> > English: <a href="http://www.sraoss.co.jp/index_en.php" target="_blank">http://www.sraoss.co.jp/index_en.php</a><br>
>> > Japanese: <a href="http://www.sraoss.co.jp" target="_blank">http://www.sraoss.co.jp</a><br>
>> ><br>
>> >> Sorry . I missed it.<br>
>> >><br>
>> >> Here is the log file.<br>
>> >><br>
>> >> --Aravinth<br>
>> >><br>
>> >><br>
>> >> On Wed, May 9, 2012 at 2:07 PM, Tatsuo Ishii <<a href="mailto:ishii@postgresql.org">ishii@postgresql.org</a>><br>
>> wrote:<br>
>> >><br>
>> >>> > The code you have sent is same in child.c.<br>
>> >>><br>
>> >>> No.<br>
>> >>><br>
>> >>>        pool_log("r: %f total_weight: %f", r, total_weight);<br>
>> >>><br>
>> >>> You need to add the line above to get usefull information.<br>
>> >>> --<br>
>> >>> Tatsuo Ishii<br>
>> >>> SRA OSS, Inc. Japan<br>
>> >>> English: <a href="http://www.sraoss.co.jp/index_en.php" target="_blank">http://www.sraoss.co.jp/index_en.php</a><br>
>> >>> Japanese: <a href="http://www.sraoss.co.jp" target="_blank">http://www.sraoss.co.jp</a><br>
>> >>><br>
>> >>><br>
>> >>> > I have attached the log file. Please check<br>
>> >>> ><br>
>> >>> ><br>
>> >>> > --Aravinth<br>
>> >>> ><br>
>> >>> ><br>
>> >>> > On Tue, May 8, 2012 at 6:20 AM, Tatsuo Ishii <<a href="mailto:ishii@postgresql.org">ishii@postgresql.org</a>><br>
>> >>> wrote:<br>
>> >>> ><br>
>> >>> >> I suspect there's some portablity issue with load balance code. The<br>
>> >>> >> actual source code is in select_load_balancing_nodechild.c).<br>
>> >>> >> Please modify source code and connect to pgpool by using psql.<br>
>> >>> >> Please send the log output.<br>
>> >>> >> --<br>
>> >>> >> Tatsuo Ishii<br>
>> >>> >> SRA OSS, Inc. Japan<br>
>> >>> >> English: <a href="http://www.sraoss.co.jp/index_en.php" target="_blank">http://www.sraoss.co.jp/index_en.php</a><br>
>> >>> >> Japanese: <a href="http://www.sraoss.co.jp" target="_blank">http://www.sraoss.co.jp</a><br>
>> >>> >><br>
>> >>> >> int select_load_balancing_node(void)<br>
>> >>> >> {<br>
>> >>> >>        int selected_slot;<br>
>> >>> >>        double total_weight,r;<br>
>> >>> >>        int i;<br>
>> >>> >><br>
>> >>> >>        /* choose a backend in random manner with weight */<br>
>> >>> >>        selected_slot = MASTER_NODE_ID;<br>
>> >>> >>        total_weight = 0.0;<br>
>> >>> >><br>
>> >>> >>        for (i=0;i<NUM_BACKENDS;i++)<br>
>> >>> >>        {<br>
>> >>> >>                if (VALID_BACKEND(i))<br>
>> >>> >>                {<br>
>> >>> >>                        total_weight +=<br>
>> BACKEND_INFO(i).backend_weight;<br>
>> >>> >>                }<br>
>> >>> >>        }<br>
>> >>> >>        r = (((double)random())/RAND_MAX) * total_weight;<br>
>> >>> >>        pool_log("r: %f total_weight: %f", r, total_weight);<br>
>> >>>  <--<br>
>> >>> >> add this<br>
>> >>> >><br>
>> >>> >>        total_weight = 0.0;<br>
>> >>> >>        for (i=0;i<NUM_BACKENDS;i++)<br>
>> >>> >>        {<br>
>> >>> >>                if (VALID_BACKEND(i) &&<br>
>> BACKEND_INFO(i).backend_weight ><br>
>> >>> >> 0.0)<br>
>> >>> >>                {<br>
>> >>> >>                        if(r >= total_weight)<br>
>> >>> >>                                selected_slot = i;<br>
>> >>> >>                        else<br>
>> >>> >>                                break;<br>
>> >>> >>                        total_weight +=<br>
>> BACKEND_INFO(i).backend_weight;<br>
>> >>> >>                 }<br>
>> >>> >>        }<br>
>> >>> >><br>
>> >>> >>        pool_debug("select_load_balancing_node: selected backend id<br>
>> is<br>
>> >>> %d",<br>
>> >>> >> selected_slot);<br>
>> >>> >>         return selected_slot;<br>
>> >>> >> }<br>
>> >>> >><br>
>> >>> >><br>
>> >>> >> > Hi Tatsuo, Thanks for the reply.<br>
>> >>> >> ><br>
>> >>> >> > The normalized weights are 0.5 for both nodes and the selected<br>
>> node is<br>
>> >>> >> always the same node. I hope then it's srandom().<br>
>> >>> >> ><br>
>> >>> >> ><br>
>> >>> >> > Any idea to solve this srandom issue<br>
>> >>> >> ><br>
>> >>> >> ><br>
>> >>> >> > Thanks and Regards,<br>
>> >>> >> > Aravinth<br>
>> >>> >> ><br>
>> >>> >> ><br>
>> >>> >> > ________________________________<br>
>> >>> >> >  From: Tatsuo Ishii <<a href="mailto:ishii@postgresql.org">ishii@postgresql.org</a>><br>
>> >>> >> > To: <a href="mailto:aravinth@mafiree.com">aravinth@mafiree.com</a><br>
>> >>> >> > Cc: <a href="mailto:pgpool-general@pgpool.net">pgpool-general@pgpool.net</a><br>
>> >>> >> > Sent: Tuesday, May 1, 2012 4:41 AM<br>
>> >>> >> > Subject: Re: [pgpool-general: 396] strange load balancing issue in<br>
>> >>> >> Solaris<br>
>> >>> >> ><br>
>> >>> >> > First of all please check "normalized" weights are as you<br>
>> expected.<br>
>> >>> >> > Run "show pool_status;" and see "backend_weight0",<br>
>> "backend_weight1"<br>
>> >>> >> > section. You see a floating point numbers, which are the<br>
>> normalized<br>
>> >>> >> > weight between 0.0 and 1.0. If you see both are 0.5, primary and<br>
>> >>> >> > standby are given same weight.<br>
>> >>> >> ><br>
>> >>> >> > If they are ok, I suspect srandom() function behavior is different<br>
>> >>> >> > from other platforms. Pgpool-II chooses the load balance node by<br>
>> using<br>
>> >>> >> > srandom(). select_load_balancing_node() is the function which is<br>
>> >>> >> > responsible for selecting the load balance node. If you run<br>
>> pgpool-II<br>
>> >>> >> > with -d (debug) option, you will see following in the log:<br>
>> >>> >> ><br>
>> >>> >> >     pool_debug("select_load_balancing_node: selected backend id is<br>
>> >>> %d",<br>
>> >>> >> selected_slot);<br>
>> >>> >> ><br>
>> >>> >> > If backend_weight in show pool_status are fine but the line above<br>
>> >>> >> > always shows same number, it is the sign that we have problem with<br>
>> >>> >> > srandom().<br>
>> >>> >> > --<br>
>> >>> >> > Tatsuo Ishii<br>
>> >>> >> > SRA OSS, Inc. Japan<br>
>> >>> >> > English: <a href="http://www.sraoss.co.jp/index_en.php" target="_blank">http://www.sraoss.co.jp/index_en.php</a><br>
>> >>> >> > Japanese: <a href="http://www.sraoss.co.jp" target="_blank">http://www.sraoss.co.jp</a><br>
>> >>> >> ><br>
>> >>> >> >> Hi All,<br>
>> >>> >> >><br>
>> >>> >> >> I am facing a strange issue in load balancing with replication<br>
>> mode<br>
>> >>> set<br>
>> >>> >> to<br>
>> >>> >> >> true in Solaris. Load balancing algorithm always select the same<br>
>> node<br>
>> >>> >> >> whatever may be the backend weight<br>
>> >>> >> >><br>
>> >>> >> >> Here is the scenario.<br>
>> >>> >> >><br>
>> >>> >> >> I have a pgpool installed installed in 1 server<br>
>> >>> >> >> 2 postgres nodes in other 2 servers<br>
>> >>> >> >> replication mode set to true and load balancing set to true<br>
>> >>> >> >> backend weight of the 2 nodes is 1.<br>
>> >>> >> >><br>
>> >>> >> >> When I fire the queries manuall using different connections or<br>
>> using<br>
>> >>> >> >> pgbench all the queries hit the same node. Load balancing<br>
>> algorithm<br>
>> >>> >> always<br>
>> >>> >> >> select the same node.<br>
>> >>> >> >> No effect in changing the backend weight. Only when I set backend<br>
>> >>> >> weight to<br>
>> >>> >> >> 0 hits go to the other server.<br>
>> >>> >> >><br>
>> >>> >> >><br>
>> >>> >> >> I face this issue only in solaris. The same setup in other<br>
>> servers (<br>
>> >>> >> centos<br>
>> >>> >> >> ,RHEL, ubunt etc) does the load balancing perfectly.<br>
>> >>> >> >><br>
>> >>> >> >> Also tries various postgres versions and pgpool version with same<br>
>> >>> >> result.<br>
>> >>> >> >> But every version runs fine in other servers.<br>
>> >>> >> >><br>
>> >>> >> >> Has anyone faced this issue?<br>
>> >>> >> >><br>
>> >>> >> >> Any information would highly helpful.<br>
>> >>> >> >><br>
>> >>> >> >> Regards,<br>
>> >>> >> >> Aravinth<br>
>> >>> >> _______________________________________________<br>
>> >>> >> pgpool-general mailing list<br>
>> >>> >> <a href="mailto:pgpool-general@pgpool.net">pgpool-general@pgpool.net</a><br>
>> >>> >> <a href="http://www.pgpool.net/mailman/listinfo/pgpool-general" target="_blank">http://www.pgpool.net/mailman/listinfo/pgpool-general</a><br>
>> >>> >><br>
>> >>><br>
>> > _______________________________________________<br>
>> > pgpool-general mailing list<br>
>> > <a href="mailto:pgpool-general@pgpool.net">pgpool-general@pgpool.net</a><br>
>> > <a href="http://www.pgpool.net/mailman/listinfo/pgpool-general" target="_blank">http://www.pgpool.net/mailman/listinfo/pgpool-general</a><br>
>> > _______________________________________________<br>
>> > pgpool-general mailing list<br>
>> > <a href="mailto:pgpool-general@pgpool.net">pgpool-general@pgpool.net</a><br>
>> > <a href="http://www.pgpool.net/mailman/listinfo/pgpool-general" target="_blank">http://www.pgpool.net/mailman/listinfo/pgpool-general</a><br>
>> _______________________________________________<br>
>> pgpool-general mailing list<br>
>> <a href="mailto:pgpool-general@pgpool.net">pgpool-general@pgpool.net</a><br>
>> <a href="http://www.pgpool.net/mailman/listinfo/pgpool-general" target="_blank">http://www.pgpool.net/mailman/listinfo/pgpool-general</a><br>
>><br>
</div></div><br>_______________________________________________<br>
pgpool-general mailing list<br>
<a href="mailto:pgpool-general@pgpool.net">pgpool-general@pgpool.net</a><br>
<a href="http://www.pgpool.net/mailman/listinfo/pgpool-general" target="_blank">http://www.pgpool.net/mailman/listinfo/pgpool-general</a><br>
<br></blockquote></div><br></div>