December 2006

Monthly Archive

Enterprise Design Patterns – An Introduction (Part 1 of the Series)

Posted by Aurelio Pascual on 14 Dec 2006 | Tagged as: Java

A software application’s main goal is to provide the user with a reliable, useful, and correct experience. However, as software grows overtime, so does complexity, and this leads to a variety of problems that could affect the reliability and performance of the application. The growth in complexity does not only refer to the lines of code but also includes the hardware. Design patterns address these software and hardware issues. Design pattern, by definition, is a repeatable solution for a commonly-occurring software problem, and they all came from developers and architects who have years of experience dealing with these software problems. But before we dive-in to the common design patterns being used today, let us discuss first the software requirements that these design patterns addresses. These are called the software “ilities”.

  1. Performance – this is very important. In a website for example, if your website is slow, you’re going to lose your customers.
  2. Modularity – your application should be composed of several parts (called modules) in order for different pieces of your application to run on different boxes at the same time.
  3. Flexibility – your system should have the ability to adapt in a timely and cost-effective manner whenever there is an external/internal change. That means if there are some changes to be done, your system can be changed without going through some big development cycle.
  4. Maintainability - you might need to change database vendors, and update your system quickly. You might get obscure bugs and need to track them down ASAP. Your system needs to be maintainable.
  5. Extensibility - the guys over in marketing might need a new feature to land that big client. Your users might demand that you support a brand new feature that their browsers have. Your system had better be extensible.

The items discussed above are called the “non-functional” requirements of software. These requirements will be easily met using design patterns. Continue Reading »

Modeling Queuing Systems Using Markov Chains

Posted by Bobby Corpus on 10 Dec 2006 | Tagged as: Performance

Have you ever notice how various establishments make people line in a certain way? Have you gone to a bank and noticed a number of tellers servicing each client but there is only one line? Wouldn’t it be more natural to let people line up before each teller like you see in a grocery? The way customers are lined up in a server or system of servers is called Queueing Discipline.
In this article, we will learn how various queuing disciplines will affect the values of the performance metrics. We will use continuous markov chain analysis that we learned in the last article.

Motivating Scenario

Assume that the counter of a certain fast food store is arrange in a 2-stage way. The customers first place their order in counter 1, pays the cashier and proceeds to counter 2 to wait for their order to be picked up. Let $a$ be the rate at which customers arrive, $b the rate at which customers places their order and also the rate at which they leave the second counter. Let us draw the markov chain diagram of this system.

Each state is described by two numbers. The first number refers to the number of customers in the first counter. The second number refers to the number of customers waiting at the second counter. For example, state 00 mean that there are no customers being serviced. State “12″ mean that one customer is in counter 1 and 2 customers in counter 2. The blue arrows represent arrivals at rate a and red arrows are represent the rate of customers going to counter 2 and those leaving the counter 2.

markov1.png

Let us examine the four states in the diagram below. There is a blue arrow from state “00″ to state “10″ because when the first customer arrives, the first station will have 1 customer but no one in line yet in counter 2. This means that when the first customer arrives, the system will be in state “10″. There is an arrow from state “10″ to “01″. The means that the first customer is already in counter 2 to pickup his/her order but no new customer has arrived yet. There is a red arrow from state “01″ to “00″. This means that the single customer has already picked up his/her food and has left leaving the system with no customers at both stations. Notice that there is no arrow from state “10″ to “00″ because the customer who is in counter 1 cannot just leave the system but has to go to counter 2 before leaving.

markov2.png
Balance Equations
Now that we have understood why the arrows point from one state to the next, we now setup the balance equations. At steady state, the sum of flows going to one state must equal the sum of flows going out of that state. By definition, the flow along an arrow is equal to the rate along the arrow multiplied by the probability of the system being in the current state.Let us do the balance equation for state “00″. There is one arrow going to state “00″ and one arrow going out of state “00″. Therefore the flow going to state “00″ is equal to the rate going from state “01″ to “00″ multiplied by the probability of the system being in state “01″ : $bP_{01}$. This is equal to the flow going out of state “00″ to state “10″: a*P00. Therefore,we have,

\[a P_{00} = bP_{01}

Let us now compute the balance equation for state “01″. As you can see, there are 2 arrows out of state “01″ and one arrow going into state “01″. The balance equation is therefore:

a P_{01} + b P_{01} = b P_{10}

Doing this for all states, we get the following balance equations:

\begin{gather*} aP_{02} + bP_{02} = b P_{11} + b P_{03}\\  b P_{03} = bP_{12}\\ aP_{00} + bP_{11} = bP_{10} + aP_{10}\\ aP_{01} + bP_{12} + bP_{20} = bP_{11} + bP_{11} + aP_{11}\\bP_{12} + bP_{12} = aP_{02} + bP_{21}\\ bP_{20} + aP_{20} = aP_{10} + bP_{21}\\ bP_{21} + bP_{21} = aP_{11} + bP_{30}\\ b P_{30} = a P_{20}\end{gather*}

We add to these equations the condition that the sum of all probabilities is equal to 1:

\[P_{00} + P_{01} + P_{02} + P_{03} + P_{10} + P_{11} + P_{12} + P_{20} + P_{21} + P_{30} = 1

Solving for the probabilities using elementary algebra, we get the following:

\begin{align*}P_{01}&=\frac{ab^2}{b^3+2ab^2+3a^2b + 4a^3}\\P_{02}&=\frac{a^2b}{b^3+2ab^2+3a^2b + 4a^3}\\P_{03}&=\frac{a^3}{b^3+2ab^2+3a^2b + 4a^3}\\P_{10}&=P_{01}\\P_{11}&=P_{02}\\P_{12}&=P_{03}\\P_{20}&=P_{02}\\P_{21}&=P_{03}\\P_{03}&=P_{30}\\P_{00}&=(b/a)P_{01}\end{align*}

A simple Example

Suppose that customers arrive on the average of 1 customer per minute and can place and pay for their order in 2 minutes. After that they wait on the average of 2 minutes at the second counter to take out their order. Using the formula above, we have $a = 1$ and $b=2$. We can now solve for the probabilities by substituting these values to the above formula.

\begin{align*}P_{01}&= \frac{ab^2}{b^3+2ab^2+3a^2b + 4a^3} = \frac{1\cdot 2^2}{1^3+ 2\cdot 1\cdot 2^2 + 3\cdot 1^2\cdot 2 + 4\cdot 1^3}\\&=\frac{2}{13}\end{align*}

Computing the rest of the values, we get the following table:

P00 4/13
P01,P10 2/13
P02,P11,P20 1/13
P03,P12,P21,P30 1/26

We can compute for the Utilization of the first counter by using it’s idle time. Notice that the first counter does not have anything to do when there are no customers lining in front of it. This happens in states P00, P01, P02 and P03. Notice that these states have the first number equal to 0 (which means: no customer in that counter). Therefore, the utilization is equal to 1 minus the idle time of counter 1, i.e,

\begin{align*}U_\text{counter 1} &= 1 - P_{00} - P_{01} - P_{02} - P_{03}\\ &=\frac{11}{26}\end{align*}

Using the Utilization law we learned in a previous article, we can compute the throughput of counter 1 to be:

\begin{align*}X_\text{counter 1} &= \frac{U_\text{counter 1}}{S_\text{counter 1}}\\ &=\frac{11/26}{2} \\&=\frac{11}{52}\end{align*}

This happens to be the system throughput also since each customer will visit a counter only once per transaction.

Now that we know how to model using markov chains, in the next article, we will analyze other queueing disciplines and compare them according to throughput and response time.

AJAX: Simple yet powerful!

Posted by Clint Barbosa on 03 Dec 2006 | Tagged as: Articles

AJAX is perhaps one of the hottest buzzwords in web development. I first saw AJAX in action in google mail. When I clicked one of my emails, only the bottom pane refreshed and displayed the email content. I was really amazed and instantly thought of the person who invented this technique.

According to mr. wickipedia “The first use of the term in public was by Jesse James Garrett in February 2005. Garrett thought of the term while in the shower, when he realized the need for a shorthand term to represent the suite of technologies he was proposing to a client.”

So what does Ajax mean? Its not a brand of soap which we are all familiar with. AJAX stands for “Asynchronous JavaScript and XML” . The word “Asynchronous” means irregular or not synchronized. In computer communications, the term is usually applied to data transmitted irregularly rather than as a steady stream. Meaning it has a lot more to do with user interaction. As another example, consider a telephone and a ham radio. The telephone is asynchronous because you can talk whenever you like even when the other party is talking. However, when using the ham radio, you need to wait for the other party to stop speaking or to release the talk button before you can get the chance to talk again. The operation of a ham radio is said to be synchronized.

In an Ajax application the same thing happens with your page. You can see the result of a certain pane or region you want to see in your page without refreshing the whole page. A good example would be a simple text box name lookup. Whenever you type an entry, the page refreshes only that part which shows the relevant information. This information is dynamically retrieve by the page from the server.

It is easy to see that AJAX saves you a lot of bandwidth because you only download the data that changes and not the whole page. Furthermore, the web UI becomes more responsive as you don’t have to wait a long time for that part to refresh as compared to the whole page being refreshed.

However, AJAX is a new technology and as such is not supported in older browsers. It is supported only IE version 6 and the latest versions of Mozilla. Also, different browsers have some slightly different implementations of AJAX, so whenever you develop in AJAX, you should tailor it to the browser used by the user. AJAX also breaks the back button support: data is reset when the back button is pressed.

AJAX is a simple yet extremely powerful technology. With a little creativity, you can already do a lot to make your page highly interactive. To see how simple AJAX is, see the sample code below.

ajax_code.JPG

You only need to know one Javascript object, namely the XMLHttpRequest. To send a request, you specify the request method and the path relative to the server. The third parameter to the “open” method is a Boolean to specify whether the request is asynchronous or not. You should specify “true” for this parameter. When the server response is received, you can get the response as a string from the req.responseText variable.