Tuesday, June 17, 2008

Clustering patterns

As usually is the case in most of the software problems we have identified patterns which solve the most common known problems. Similarly we have patterns for know problems in case of availability and performance as well.

There are 2 well known patterns for clustering which i would discuss in this post

1) Load Balanced Clustering

Any application server runs on a piece of software which is running on a piece of hardware. Which basically means that the server definitely has a performance threshold after which the performance would fall below expectations of the client. Even if we take the world's most advanced hardware it would have a limit to number of requests which it can server for a given piece of software. Once the number of requests increase over this number the server has to be scaled up (Not possible in this case as we already are on most advanced piece of hardware) or scaled out (Feasible option). To scale out an application running on such hardware we can add some more servers and cluster them using a load balancer.

The load balancer would act as the virtual resource to the clients and redirect the requests to appropriate physical servers lying behind it. So the network would look like the following...





The load balancer can delegate the requests to various servers based on various algorithms like
a) Round Robin :- Every one gets equal amount of requests
b) Weighted Round Robin :- A certain weightage given to servers based on hardware configuration by the administrator. The Load Balancer can decide based on these weightages to redirect the incoming requests to appropriate server
c) Least Connection :- Whichever server is serving the least connections gets the next request
d) Load Based :- Whichever server has the least load gets the next request

Normally a load balancer is intelligent enough to detect the failures of a particular server in the network and can stop sending requests to the failed node.
One of the interesting thing which goes down to the level of application design if we plan to deploy our application on a load balanced cluster is the state management. Normally applications store the Session information in the container provided objects (Session object in ASP.NET), now by default these session objects reside in the memory of the application server on which the request has been processed. In case the next request goes to a different server node in the cluster that node will have no clue about the session state stored in the memory of a different server in the cluster and important data might be lost in this case.
There can be 3 solutions to this problem
a) Use a external state server or state service to store the session object
b) Use an algorithm on the load balancer such that a request coming in the same session context always gets redirected to the same node in the cluster. (Server Affinity)
c) Ask each server to broadcast the session state in the whole . (Asynchronous Session state management ). This would be a cheap solution however with lot of network chaos inside the cluster.

Now one of the important questions which remains is to define what exactly is this load balancer. Basically it can be a piece of Software (Installed on one of the servers in the cluster) or Hardware (Special routers with intelligence for load balancing) which act as the gateway to the external world.
This kind of clustering is a good choice to meet the non functional requirements for high availability and Scalability

2) Failover Clustering

Some applications have a major requirement in terms of availability. e.g. the application can't go down even for an upgrade/patching. In such a case we can go for a configuring a failover cluster. In this pattern the idea is that a standby server is waiting to take over the primary server in case it goes down due to some reasons.
To detect that the server has gone down there can be 2 ways
a) Pull Heartbeat :- The standby server keeps checking the availability of primary server after a specified interval. In case it finds that the sever is not responding it assumes that the primary server is down and takes over the job and starts working on requests.
b) Push Heartbeat :- In this case the primary server keeps telling the standby server that its up. If the secondary server doesn't receive the heartbeat for a specified period of time it takes over the job and starts processing the requests.

In either cases before the standby server starts processing the requests it needs to synchronize with the primary server in order to be in exact same state so as to honour any open sessions/ transactions. Here are the strategies which can be used to do the same
a) Transaction Log :- Everytime the state of the primary server changes it logs the change in a transaction log. The log is synchronized with the standby server periodically and it brings itself into the same state as primary server. As soon as secondary server finds out that it has to take over it synchronizes with the latest transaction log so as to come into the same state in which primary server was before it went down. Now it is ready to take over and serve the requests....
b) Hot Standby :- In this strategy any change in the state of primary server is immediately sent to the secondary server to copy. The advantage is that as soon as the primary goes down the secondary can take over without any delay.
c) Shared Storage :- The state of both the servers is maintained on a external storage device. So it is as good as Hot Standby. It can be more or less performant based on how we synchronize the state in Hot Standby case and how responsive the is the external device to store/retrieve the state.

Another important aspect of this pattern is determining the active server. If multiple servers in a cluster assume that they are the active servers then unexpected behaviors like deadlock and data corruption may occur.

It is very important to design the cluster in such a way that we do not loose the performance. Additionally it might be a bit costly since standby server is normally not used unless there's a failure of primary one.

Now that i have summarized the 2 clustering patterns in this post the next logical step would be to setup an IIS cluster for each pattern. It should result in a new post in this series :). Here's what i plan to do ....
1) Have 2 IIS Servers on a network
2) Install a single ASP.NET Hello World applcation on it
3) Configure a Failover cluster between the 2 IIS instances and test that it works
4) Configure a software load balancing cluster and test that it works (May need a load runner kind of tool to simulate many requests).

~Abhishek



Thursday, June 12, 2008

Non functional requirements like Availibility,Scalability...

Any application being built in today's world has lot of non functional requirements. 2 of the non functional requirements are Availability and Scalability.
Availability is the ability of the sysytem to serve the requests of the users for the measurable amount of time. It is a major factor when the software is deployed in a production environment. Lots of business processes will depend on the availability of the system and if the system is unavailable then it is more often then not loss to the customer using the system. If the application is a e-biz. application then its a direct loss of money while if application is something else then its a loss in productivity and hence indirect loss of money to the customer.
In a SaaS scenario availability will be of even more concern since downtime of the service may translate into the breach of a legal contract between provider and consumer of the service and can result in bigger losses for the provider of the service.
Scalability of a system can be defined as ability of the system to be able to serve the increasing demands of the system while stealing maintaining the acceptable performance levels. Once a system is online and is a success then its but natural that the it would be used by more and more people and hence it is but natural that the system would have to handle the increasing demands.
Now a system can either be Scaled Up or Scaled Out based on the increasing demands. Scaling Ua system would normally mean increasing the hardware (memory/ more processors) of the server to enable it to perform faster. Scaling Out a system would normally mean that we increase the number of servers in the landscape and try to meet the performance standard with more servers.

I believe These 2 non functional requirements will be affecting the design application .
How is something i will try to figure out and may be post it in a different post.

Clustering is a solution to meet these non functional requirements. Basically clustering is nothing but to present a group of physical servers to the client as 1 virtual resource. The requests coming from the clients to this virtual resource can be redirected to the physical servers based on various algorithms.
A logical view of such an arrangement would look something like this..


So the above picture basically depicts that we have a cluster of server 1 and server 2 which is handling requests from client based on some kind of request routing done by the virtual resource.

There are various ways of configuring a cluster based on what kind of requirements we have. I'll look into them and post on a different post....

~Abhishek

Wednesday, June 11, 2008

Clustering !!!!

Clustering has always been a term to me rather then a topic. A few days back while having a discussion about application availability, scalability and performance i suggested clustering as a solution.
However i myself was and am not sure of what topic could this term possibly unearth for me.
So after avoiding to read on this topic for around 2 weeks now finally i decided to blog it as an action item.
I'll be reading about clustering soon and would come up with a post or 2 with the label Clustering (And added labels as required for the topics the term unearths for me)

~Abhishek

Thursday, May 29, 2008

Implementing logic in the proxy and consuming the service in .NET

First the good news :)
I managed to create the service and was able to consume it from .NET.
Here were the open questions from the last post....
1) How to write some logic in the server proxy
2) Where and how to find the wsdl with binding information so that i can consume it from .NET

In order to write the logic into proxy i went to the package in which i generated the proxy. In that package i found that an interface has been generated for the message interface we generated in ESR and a class to implement the interface. I found the method instance method of the class and went ahead editing the method implementation. My first unassisted ABAP code. Here's how it looked like....


OUTPUT-GET_EMPLOYEE_OUTPUT-ID = INPUT-GET_EMPLOYEE_INPUT.
OUTPUT-GET_EMPLOYEE_OUTPUT-NAME-FIRST_NAME = 'Abhishek'.
OUTPUT-GET_EMPLOYEE_OUTPUT-NAME-LAST_NAME = 'Kumar'.


Once done i went to the transaction SOAMANAGER. This is the new transaction which replaces the transactions WSADMIN and WSCONFIG. This opened a webdynpro UI with a tab Business Administration on which there's a link Web Service Administration. There i can search for the design time component i want to configure. (EmployeeService) in my case. Once selecting the service i can go to Configurations tab where i select to Create a Service. I can choose a name for the service and binding. Whatever i choose here appears in the final wsdl as service and binding. Once done I can choose a type of authentication. I chose http authentication. and saved the configuration.

On the same page i found the link to the wsdl with all the binding and port information. On having a look at the wsdl i confirmed that binding and service tags are available.
Copy the link to the wsdl and try setting the reference to this wsdl in Visual Studio. Once done i am able to call the service easily from .NET.

Now the second question which was how to add more then one operation to the Message Interface. This is a limitation in 700 release of BASIS. And unfortunately the sandbox system has a 700 release of BASIS. According to some documentation i found i can add more then 1 operations in the message interface. So i parked it for the time being.....

~Abhishek

PS :- This was my hello world to the world of ABAP. i.e. a first program in ABAP. This post is the last in the series of blogs i started on May 23rd 2008 :)

Tuesday, May 27, 2008

Generating a Proxy

Here's what i did next. I just added a message interface called EmployeeService in the Message interfaces of my . I marked it as inbound synchronous method in the option. I couldn't find much documentation about what the various options mean however i assume that inbound means inbound message coming from client to the server and synchronous means that server would process them and give the results back to client then and there itself.
Now i selected the input and output messages and there you go . I got a nice wsdl which looks like the following....

<?xml version="1.0" encoding="ISO-8859-1"?>

<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:p1="http://sap.office.tst" name="EmployeeService" targetNamespace="http://sap.office.tst">
<wsdl:types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://sap.office.tst" targetNamespace="http://sap.office.tst">
<xsd:element name="GetEmployeeInput" type="EmployeeId" />
<xsd:element name="GetEmployeeOutput" type="Employee" />
<xsd:simpleType name="EmployeeId">
<xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">
a64268c22be811dda00f000bcd9b93dd
</xsd:appinfo>
</xsd:annotation>
<xsd:restriction base="xsd:string" />
</xsd:simpleType>
<xsd:complexType name="Employee">
<xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">
a644d9c02be811dd90e2000bcd9b93dd
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="Id" type="xsd:string">
<xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">
4ca5845028aa11ddb1c2001321f4509b
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="Name" type="Name">
<xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">
4ca5845128aa11ddb4a1001321f4509b
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Name">
<xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">
a64994b02be811ddc2e4000bcd9b93dd
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="FirstName" type="xsd:string">
<xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">
93b077b028aa11ddcc0b001321f4509b
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="LastName" type="xsd:string">
<xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">
93b077b128aa11ddb07c001321f4509b
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
</wsdl:types>
<wsdl:message name="GetEmployeeInput">
<wsdl:documentation>
Input to GetEmployee Operation
</wsdl:documentation>
<wsdl:part name="GetEmployeeInput" element="p1:GetEmployeeInput" />
</wsdl:message>
<wsdl:message name="GetEmployeeOutput">
<wsdl:part name="GetEmployeeOutput" element="p1:GetEmployeeOutput" />
</wsdl:message>
<wsdl:portType name="EmployeeService">
<wsdl:operation name="EmployeeService">
<wsdl:input message="p1:GetEmployeeInput" />
<wsdl:output message="p1:GetEmployeeOutput" />
</wsdl:operation>
</wsdl:portType>
<ifr:properties xmlns:ifr="urn:com-sap:ifr:v2:wsdl">
<ifr:category>
ifmmessif
</ifr:category>
<ifr:methods>
<ifr:method name="EmployeeService">
<ifr:isSynchron>
true
</ifr:isSynchron>
<ifr:isInbound>
true
</ifr:isInbound>
<ifr:interfaceCategory>
inbound
</ifr:interfaceCategory>
</ifr:method>
</ifr:methods>
<ifr:messages>
<ifr:message name="GetEmployeeInput">
<ifr:messType>
ifmmessage
</ifr:messType>
<ifr:technicalNamespace>
http://sap.office.tst
</ifr:technicalNamespace>
</ifr:message>
<ifr:message name="GetEmployeeOutput">
<ifr:messType>
ifmmessage
</ifr:messType>
<ifr:technicalNamespace>
http://sap.office.tst
</ifr:technicalNamespace>
</ifr:message>
</ifr:messages>
</ifr:properties>
</wsdl:definitions>

As soon as i was done with this i though of generating a .NET proxy for this wsdl. (Me being a .NET developer i couldn't control my instincts and stay away from Visual Studio too long :) )

Anyways i tried to generate a proxy and failed. Basically nothing is generated. On looking closely at the wsdl i found that wsdl:service and wsdl:binding tags are missing. Which is understandable. If i was designing the ESR i wouldn't want the information about binding and implementation address in my repository. I would probably keep it somewhere else like UDDI. This is an open question that i need to figure out now. Where doesn SAP keep this information. I'll touch this back once i am sure that implementation works.

So leaving the visual studio i came back to my ABAP system and started sproxy to generate a implementation proxy for my wsdl. After struggling a lot with package concept of ABAP i was suggested to make the proxy as a local object. I still can't figure out why it can't be a server object.... Everyone i contacted gave me different reasons however i chose to believe that i do not have appropriate permissions to create a server side object. (Sad and interesting, since this is a sandbox i thought i have all the permissions)

So i have managed to generate a proxy for this wsdl in ABAP and now comes the first place where i would code. All i want to do is to give back the employee with some hardcoded name and passed id from the method. Once i am able to do this i would actually go ahead and find the answer to my first question i.e. where to find the binding and service info for this interface.

Another open question which looms large is to add another method to this interface. I choose to address this at the end.

~Abhishek

Sunday, May 25, 2008

Show a document on the post

One of my friends wanted to post a pdf document on the blog. On doing a quick google i found a nice tool to post documents on the blog.
Check out http://www.scribd.com/ for finding how to upload and show documents on your blog.....

~Abhishek

Friday, May 23, 2008

Posting xml on the blog

Here's a simple javascript web application application that will format source code text into html for inserting into your blog.

http://formatmysourcecode.blogspot.com/

~Abhishek