Create a table as result of select query

If you want to dump the result of your select query into a table, this query will help in Oracle or MySql.

Create table newTable select * from oldTable where condition=true;

In case of MsSql this will work

Select * into newTable from oldTable where condition=true;

Difference between web server and application server

We  use terms application server and web server interchangeably these days. Historically a web server was supposed to serve static html pages over http protocol. Then web servers started serving scripting languages like ASP, JSP, PHP etc. For complex application which needed services connection pooling, object pooling, messaging, transaction management were supposed to use application server.

I said historically because with time the distinguishing line has narrowed down. Most of the web servers have started providing features of application servers with plugins and add-ons. Some exmples of web servers- Apache HTTP (PHP), Tomcat (Servlet container, newer versions have EJB container) etc. Application server examples are JBoss, Websphere etc.

Clustering

A cluster in simple terms is group of similar things, in this case computers or servers. A more refined explanation would be that a cluster is group of computers, working together in such a way that for end user it is one single machine. This is close to what I discussed about implementation of virtualization, so yes clustering is a form of virtualization.

But when we are strictly talking about software architecture, we are actually talking about using cluster for load balancing or handling failover. For a simple web application, this would mean creating 2 or more similar server machines, which are maintained in a cluster. There is a single point of entry which dictates which server from cluster should fulfill incoming request. This is load balancing. The server at the entry point can use any algorithm like round robin or check the actual load on a server to assign a request to one of the servers in the cluster. At the same time if one of the machine goes down in cluster for some reason, other servers can share the load and end user will never know about the problem occurred at backend.

http://msdn.microsoft.com/en-us/library/ff649250.aspx

http://en.wikipedia.org/wiki/Cluster_%28computing%29

Grid Computing

What is a Grid? In definition it is nothing but some horizontal and vertical lines cutting each other. Something like

grid

How is that related to grid computing? Not actually. But if you think that there is a computer node available at each intersection of horizontal and vertical line, we will get close.

What exactly is grid computing? Think of the fact there are many average computers connected to each other and can share their processing power, how fast it can deliver solution. It is form of implementation of distributed computing and parallel computing. It can help using many average sized computer and giving impression on a super computer processing power.

http://computer.howstuffworks.com/grid-computing.htm
http://www.gridcafe.org/grid-in-30-sec.html
http://en.wikipedia.org/wiki/Grid_computing

Service Oriented Architecture

Service Oriented Architecture or SOA is a way to design a software application, in which we divide each logical unit/ component of the system as self sufficient service. The idea is not very new and has its roots in distributed computing. But the concept of SOA has gained more popularity recently due to the fact that IT is going very fast changes now as compared to past. Technology that is hot today might become obsolete in an year. SOA guarantees insurance against such a change. How? Let’s start with a very small example, a one page form submission for online registration to say a college

Let’s say I choose JSP or Servlets to implement this simple solution. When user hits the link, JSP code gets executed and serves HTML form page to user. On submit of request, another or same JSP file gets called which processes the form. Let’s say now I want to change my frontend experience, and say want to use cool flash, or html 5 or some JavaScript framework for better user experience. Its a bit change as my UI is tightly coupled with backend. Same problem will occur if I want to change my server side language, and want to use dot Net or PHP instead of Java.

SOA comes to help in this scenario. Let’s if I have used a plain HTML/ Javascript frontend and created a Java Webservice at backend (receiving and sending say XML request and response), both the areas are now loosely coupled and are independent of each other. I could simply take out HTML and replace with flash UI or something new that came up recently, without even notifying the server side code, which will keep on serving XMLs. Similarly I could take out Java Webservice and replace with dot Net or something else without caring about front end as long as it parses similar request and sends back response.

The above example might not explain the exact usage of SOA but it gives some picture. We can extend the above example, by thing of a complex system say a banking system, which has multiple components like retail banking, corporate banking, account management, loan management, customer relation management etc. If all these are created in tightly coupled fashion, it will be very difficult to manage and maintain a system, forget about upgrade. Whereas if the system is implemented in SOA manner, with small manageable services components, it is much more easier to maintain and upgrade.

http://en.wikipedia.org/wiki/Service-oriented_architecture

http://en.wikipedia.org/wiki/Distributed_system

Virtualization

Virtual, as the word hint, is something that is not real, but gives feeling of being real. In computer world, my first interaction with virtual machine was at the very beginning in school days, when we were made to work on dumb terminals, which had only monitor and keyboard. The terminal used to be attached to a central powerful machine which would provide processing power and memory requirements.

That is a very crude example of virtualization. With hardware cost going down in last few years, the need of dumb terminals has evaporated. But with cloud computing coming into picture, virtualization in IT industry has reached to new scales. With cloud computing it is convenient and important to manage virtual machines based on requirement or load on the application.

Virtualization goes beyond a virtual machine (hardware virtualization, software virtualization, storage virtualization, network virtualization are key), but for sake of this posts simplicity, I will stick to virtual machines. A virtual machine is simply a machine which does not exist in real, but can be used as a real machine. The advantage of this type of arrangement is maximum usage of hardware and hence cost efficiency.

Hypervisor is the key software component which helps running multiple operating systems (and hence machines) on one system. Read here on hypervisors.

Suggested reads

http://en.wikipedia.org/wiki/Virtualization
http://en.wikipedia.org/wiki/Hypervisor
http://en.wikipedia.org/wiki/Virtual_machine
http://www.zdnet.com/blog/btl/virtualization-software-revives-dumb-terminals-cuts-it-costs/9808
http://www.webopedia.com/TERM/V/virtualization.html

Shared lock- Effecting Select query’s performance

A shared log in SQL query is applied by default by SELECT statements. The difference between Shared and exclusive locks is that exclusive lock will stop any update on the data being locked, whereas shared lock suggests the select query to wait if some update or insert operation is in progress for the row.

Shared lock will not stop any other request from selecting or updating the records.

For example- select * from employee;

The above statement will fetch employee data from employee table, but if at the same time some insert or update query is executing, it will impact the performance of select query as it has to wait for other operation (on the row/ page it is trying to read) to finish.

Workaround: If we are sure that other operations executing at the same time are not going to impact my select query, i.e. I am ok to read a few old records/ dirty read, Sql provides us keyword NOLOCK

select * from employee with (NOLOCK);

This will make sure our select query does not get impacted by insert and updates running at the same time, though we might have problem of dirty read.

Workaround 2: With NOLOCK we know we can have a dirty read problem, to avoid that, we can use READPAST. This will make the select query skip any rows being updated at the query time and hence avoids dirty reads, So we are achieving our goal of not waiting for insert/ update operations to be over plus. On the downside, the resultset will miss some of the records.

select * from employee with (READPAST);

Complex Event Processing

Let’s start from understanding what is an event. The dictionary explains events as “a thing that happens, of importance”. Second part, i.e. “of importance” is a bit tricky, some events can be important for one but not for another. For example clicking anywhere on your computer screen is actually an event, but it does not result into an action, but clicking on some icon is event of importance as that will open up some application. In a banking system an event will be when someone withdraws money, checks balance, closes account or open account etc. In a computer game there will other type of event like, jump, run, hit, kill, fire etc.

Event processing is what should be done when the event occurs. For example, what to do when a specific icon on a window is clicked? What should be done when an event of withdraw money occurs – check if pin/ signature is correct, check if there is sufficient balance, pay money to person, reduce the amount from balance etc.

Now next level is to handle complex events. A complex event is an event which is result of many events occurring in relation to each other forming a definite pattern.

We are receiving following information from a ground
1. A man is kicking a football.
2. There are 2 goal posts set on opposite ends of ground.
3. There are few men in the ground trying to take control of same ball.

We can deduce a complex event – a football match.

This kind of pattern detection and complex event processing is used in Operational Intelligence solutions to identify opportunities and threats. For example banks use this kind of event processing to detect and take action on fraud detection. Say if a credit card transaction seems out of place, the amount deducted is not supported by historical data about the card usage, or the card is being used too frequently or the card is used at a location which is not in proximity of the consumer address, this kind of events, combination can generate an event for “CheckCreditCardFraud” or “StopPayment” or “RaiseAlert”.

Blue eyed boy- puzzle

This is conversation between two friends Ram and Shyam

Ram: Hey Bro, long time! How are you?
Shyam: I am good, How are you?
Ram: How are three boys, they must have grown up now. How old are they?
Shyam: Hmm, let me put it like this, if you multiply their ages, you will get the product as 36. And if you add their ages, you will get my house number.
Ram: Interesting, give me some more hint?
Shyam: Ok, my oldest son has blue eyes.
Ram: Awesome, so their ages are …

Puzzle: So what is the age of three boys?

———————————————————————

There are three hints

1. Product of the ages is 36.
2. Sum of the ages is same as house number. Interesting, we do not know house number, we will see how to use it.
3. Oldest is blue eyed boy. How is that useful?

Ok, lets start

1. Product of 3 ages is 36, so possible solutions are

1, 1, 36= 38(sum)
1, 2, 18= 21
1, 3, 12=16
1, 4, 9=14
1, 6, 6=13 *
2, 2, 9=13 *
2, 3, 6=11
3, 3, 4=10

2. Sum of the ages is house number
Looking at the above numbers, its clear that all the sums except 13 are unique, so if the house number was anything other than 13, Ram would have answered easily. But as he asked for one more hint, we now know that the house number is 13 and we are left with 2 possible solutions.
1, 6, 6=13 *
2, 2, 9=13 *

3. Oldest boy has blue eyes.
Out of the two options mentioned above, option 2 has a clear cut oldest age, i.e. 2, 2, 9. In case of 1, 6, 6, statement should have been one of the older boys or both old boys.

So ages are – 2, 2, 9