[jgroups-users] Making outstanding requests using Async methods channel.send()

Questions/problems related to using JGroups <[email protected]> Thu, 16 Feb 2017 15:24:04 -0700 (MST)
Newsgroups gmane.comp.java.javagroups.general
Message-ID <[email protected]>
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