From: Chen Huajun <chenhj@cn.fujitsu.com>
To: Scott Harrington <scotth01@sns-usa.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: performance problem of Failover Datasource?
Date: Tue, 18 Dec 2012 08:05:54 +0800
Message-ID: <50CFB362.4080701@cn.fujitsu.com> (raw)
In-Reply-To: <alpine.WNT.2.00.1212151055200.6544@turks>
References: <4DFA5A86.9030301@acm.org>
<itdn5g$eu7$1@dough.gmane.org>
<4DFA671F.2050005@acm.org>
<4DFA9704.4000209@hogranch.com>
<4DFAB403.5010309@acm.org>
<4DFAB5B8.5010603@hogranch.com>
<4DFAB9E2.4070905@acm.org>
<1334056170219-5629626.post@n5.nabble.com>
<1355303340886-5736270.post@n5.nabble.com>
<50C9B102.2060208@cn.fujitsu.com>
<CADK3HH+TLPjrrJ=cQWqZ+0B5o96xR+sTVcvqhcDU4CjyryKG2g@mail.gmail.com>
<50CA959E.4060603@cn.fujitsu.com>
<50CB29BD.6090903@cn.fujitsu.com>
<50CC2279.3090301@cn.fujitsu.com>
<alpine.WNT.2.00.1212151055200.6544@turks>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>
Thanks for you advise.
I will try to made a new patch and add load balance supporting.
--
Best Regards,
Chen Huajun
(2012/12/16 0:19), Scott Harrington wrote:
> On Sat, 15 Dec 2012, Chen Huajun wrote:
>
>> In this patch,I use Collections.synchronizedSet to synchronize within multi-threads. But i worry about locking operation is a litter frequent by Collections.synchronizedSet and may affect
>> performance. I think using keword "synchronized" explicitly instead of Collections.synchronizedSet may reduce times of locking.Is there any better suggestion?
>>
>> In addition, I have a idea. By adjusting the order of hosts we also can implement a simple load balance while all of the hosts are master or read only slave. For example: Basically pick up the
>> server randomly.If one server had dead remove it from the candidates, and retry the next server. And after a while(can be configured) re-add the dead host to the candidates because the dead server
>> may had been repaired.
>>
>> What about that?
>
> Perhaps instead you could abstract this logic into a org.postgresql.util.HostChooser interface, which would replace the HostSpec[] array that currently gets passed around.
>
> Something like this, which doesn't require synchronization but rather stores a single volatile index of the "last known good" server address (warning: coding off the top of my head).
>
> public interface HostChooser implements Iterable<HostSpec> {
> Iterator<HostSpec> iterator();
> void reportSuccessfulConnection(HOstSpec hostSpec);
> }
>
> public class SingleHostChooser implements HostChooser
> {
> private final HostSpec hostSpec;
> public SingleHostChooser(HostSpec hostSpec) { this.hostSpec = hostSpec; }
> public Iterator<HostSpec> iterator() { return Collections.singletonList(hostSpec).iterator(); }
> public void reportSuccessfulConnection(HostSpec ignored) {}
> }
>
> public class LastKnownGoodHostChooser implements HostChooser
> {
> private final HostSpec[] hostSpecs;
> private volatile int lastKnownGood = -1;
> public LastKnownGoodHostChooser(HostSpec[] hostSpecs) { this.hostSpecs = hostSpecs.clone(); }
>
> public Iterator<HostSpec> iterator() {
> int first = lastKnownGood;
> if (first <= 0) {
> return Arrays.asList(hostSpecs).iterator();
> }
> ArrayList<HostSpec> reordered = new ArrayList<HostSpec>(hostSpecs.length);
> for (int ii = first; ii < hostSpecs.length; ++ii) {
> reordered.add(hostSpecs[ii]);
> }
> for (int ii = 0; ii < first; ++ii) {
> reordered.add(hostSpecs[ii]);
> }
> return reordered.iterator();
> }
>
> public void reportSuccessfulConnection(HostSpec hostSpec) {
> lastKnownGood = Arrays.asList(hostSpecs).indexOf(hostSpec);
> }
> }
>
>
>
>
>
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: chenhj@cn.fujitsu.com, scotth01@sns-usa.com
Subject: Re: performance problem of Failover Datasource?
In-Reply-To: <50CFB362.4080701@cn.fujitsu.com>
References: <4DFA5A86.9030301@acm.org> <itdn5g$eu7$1@dough.gmane.org> <4DFA671F.2050005@acm.org> <4DFA9704.4000209@hogranch.com> <4DFAB403.5010309@acm.org> <4DFAB5B8.5010603@hogranch.com> <4DFAB9E2.4070905@acm.org> <1334056170219-5629626.post@n5.nabble.com> <1355303340886-5736270.post@n5.nabble.com> <50C9B102.2060208@cn.fujitsu.com> <CADK3HH+TLPjrrJ=cQWqZ+0B5o96xR+sTVcvqhcDU4CjyryKG2g@mail.gmail.com> <50CA959E.4060603@cn.fujitsu.com> <50CB29BD.6090903@cn.fujitsu.com> <50CC2279.3090301@cn.fujitsu.com> <alpine.WNT.2.00.1212151055200.6544@turks> <50CFB362.4080701@cn.fujitsu.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox