Re: [jgroups-users] Making outstanding requests using Async methods channel.send()
Questions/problems related to using JGroups <[email protected]> Fri, 17 Feb 2017 09:36:51 +0100
| Newsgroups | gmane.comp.java.javagroups.general |
|---|---|
| Message-ID | <[email protected]> |
Locally, each of the 25 invokers is roughly sending 4 (100/25) messages
until it blocks. When the receiver has processed a message, it
decrements the 'credits' (max of 100) to allow for an invoker to send
another message.
Now you're running 3 instances, so each receiver wil receive a total of
25 * 10000 * 3 = 750'000 messages. However, your AtomicInteger is only
local, ie. within the local JVM.
I don't know what myProtocol is doing.
So what's the question?
On 16/02/17 23:24, Questions/problems related to using JGroups wrote:
> Hi All,
>
> *Background:*
> I have a protocol run in 3 machines (servers), implementing using JGroups,
> lets says we call the protocol myProtocol. I want to benchmark myProtocol
> using code as showing below.
>
> public class Clients {
>
> private JChannel channel;
> private Invoker[] invokers=new Invoker[25];
> private AtomicInteger outstandingRequests = new AtomicInteger(0);
> private int requestToSendForEachInv = 10000;
>
> public void Clients(){
>
> //Some code to setup channel
>
> }
>
> public void viewAccepted(View new_view) {
> //some code
> }
>
> public void startSend() throws Throwable {
>
> // create sender (threads) to send requests
> for(int i=0; i < invokers.length; i++){
> invokers[i]=new Invoker(channel, requestToSendForEachInv,
> outstandingRequests);
> }
>
> for(Invoker invoker: invokers)
> invoker.start();
>
> for(Invoker invoker: invokers) {
> invoker.join();
> }
>
> }
>
> /*
> * Here I receive a replay. I need to check if the outstanding requests
> * less than 100, if so notify all invokers.
> */
> public void receive(Message msg) {
>
> synchronized (this) {
> if(outstandingRequests.decrementAndGet()<100){
> //How to notify the invokers?
> }
> }
>
> }
>
> //Sender to send write Request
> private class Invoker extends Thread {
> private JChannel channel;
> private int toSend;
> private AtomicInteger outstandingRequests;
>
> public Invoker(JChannel channel, int toSend, AtomicInteger
> outstandingRequests) {
> this.channel = channel;
> this.toSend = toSend;
> this.outstandingRequests = outstandingRequests;
> }
>
> public void run() {
> while(true) {
>
> for (int i = 0; i < toSend; i++) {
> channel.send(message);
> if(outstandingRequests.incrementAndGet()>=100){
> // How to make thread wait, is this.wait() enough?
> }
> }
>
> }
> }
>
> public static void main(String[] args) {
> Clients client = new Clients();
> client.startSend();
> }
>
> }
>
> }
>
> The client code runs in different machine (not with server machines),
> operates 25 threads (invokers or senders). Each invoker sends 10000 requests
> to myProtocol (total of 250000 requests). In Client class, there is a
> callBack method, receive(), which is called when a replay message is
> received from myProtocol.
>
> *My questions:*
> I would like to have a total of 100 outstanding requests. On other words, I
> want myProtocol always processes 100 requests at the time.
> Note that I have simplified Client class for you to make it easy to
> understand. Also, my question seems mainly related to the concurrency rather
> than JGroups.
>
> I look forward to hearing from you.
>
> Thank you
> Ibrahim
>
>
>
>
> --
> View this message in context: http://jgroups.1086181.n5.nabble.com/Making-outstanding-requests-using-Async-methods-channel-send-tp11287.html
> Sent from the JGroups - General mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
> _______________________________________________
> javagroups-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/javagroups-users
>
--
Bela Ban, JGroups lead (http://www.jgroups.org)
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot