Faster Revoking by Sending Fat Messages

Published on July 10, 2010 by Amir Sedighi

Introduction
Here is an approach to speed up object/service invoking. This solutions may apply to a web-based application or any other service that works using a series of interactions and transactions. Here I don’t refer to any specific technology or platform, because it is a pretty general technique. It is all about sending a bigger message that carries more parameters for multiple methods instead of sending multiple messages to the multiple methods. In other word this article is about favoring fatty messaging instead of chatty messaging.

Converting A “Chatty” Messaging To A “Fatty” One
Monitoring an application in runtime appears that how much a big UI transaction may consists a lot of inner interactions between client application and server side services. This may happens even between servers such as application server and database server. In many cases you need to perform a macro interaction that needs many input parameters to get finish. These input parameters may should provides by user or any other external system. Below sample shows a chatty approach that gets some input parameters at start point and some others during the process.

Assume we have below three methods in class B:

public int sum ( int a , int b ) {
	return a + b;
}

public int multi ( int a , int b ) {
	return a * b;
}

public int power ( int a , int b ) {
	int result = 1;
	for ( int a = 1 ; a < b ; a ++ ){
		result = result * a ;
	}
	return result;
}

Now if class A use to call these three methods sequentially then we will have such a sequence as below:

		A (Caller) 				B (Callee)
		----------------------------------------------------------------------
		B bObject = new B();
		firstVal = bObject.sum(1 , 2)
							B returns 3  

		secondVal = bObject.multiply( firstVal , 2 )

							B returns 3 * 2 = 6		

		thirdVal = bObject.power( secondVal , 2 )

							B returns 6 * 6 = 36

Assume B hosted in a remote machine. Something like RMI or even web-service calling. As you can see we have three remote method invoking that all are synchronized. Regardless of process consuming in B machine, we have at least 3 remote call that each one has one return value passing. Instead of this chatty talking between A and B we can use an onetime fatty calling by implementing a wrapper in B as below:

public int whatANeeds ( int a , int b, int multiValue, int powerValue ) {
	int firstVal = this.sum(a,b);
	int secondVal = this.multi(firstVal,  multiValue );
	return this.power(secondVal,  powerValue );
}

Now sequence of remote method calling will be as below:

		A (Caller) 				B (Callee)
		----------------------------------------------------------------------
		B bObject = new B();
		final = bObject.whatANeeds (1 , 2 , 2 , 2);
							B returns 36

An Old Fashion High Performance Approach
We can extend this kind of method invoking in another special that B is a RDBMS. Assume B is a RDBMS and A is the application server that calls some queries or runs some data manipulating SQL commands remotely. In this case stored-procedures could be useful. Everybody knows the most significant bottleneck is the low capacity of I/O and data transfer systems. So calling server-side methods in fatty messaging is always pretty effective in improving performance. Implementing stored-procedures in RDBMS is so old fashion for new age of developers. But it is really the fastest way that helps a business application to run faster. As a result we almost can convert multiple chatty methods invoking to a fatty one that runs faster. This could be useful everywhere in internal or external method/service invoking.

Posted in Software Engineering

One Response to “Faster Revoking by Sending Fat Messages”

  1. Anamaria Villaneva Says:

    Cheers for writing this. This addressed lots of inquiries which i had.

Leave a Reply

Categories

Archives