Thursday, October 19, 2006

Your Dominant Intelligence is Logical-Mathematical Intelligence

You are great at finding patterns and relationships between things.
Always curious about how things work, you love to set up experiments.
You need for the world to make sense - and are good at making sense of it.
You have a head for numbers and math ... and you can solve almost any logic puzzle.

You would make a great scientist, engineer, computer programmer, researcher, accountant, or mathematician.

Wednesday, October 18, 2006

Petrol engine versus diesel engine

An engine is a lump of metal which makes the vehicles go zoom. Major types of engines are petrol and diesel. The engines required to run petrol and diesel are different because petrol and diesel are different types of fuel. Petrol is a highly volatile fuel and gets ignited very easily whereas diesel is comparatively heavy and dirtier fuel. We would be talking about 4 stroke engines only, the ones used in cars.

People who know me must be wondering why am I writing this article, i being a computer engineer. Hmmm, because, i am supposed to buy a car now and have been doing some research on them. The first question I came upon was whether a petrol or a diesel car. And, all i want to do is to share all that i have learned with you people. I am still unable to decide whether i should go for ford fiesta diesel or ford fiesta petrol, the petrol verson being a lot cheaper than the diesel version.

Lets start with what does a 4 stroke engine mean. It means that the engine has 4 strokes - inlet, compression, expansion and exhaust. Lets see stroke by stroke how both engines work

Petrol Engine


Diesel Engine


Inlet stroke
> In petrol engines the mixture of air and petrol is drawn in by the falling piston
> In diesel engines only air is drawn in by the falling piston

Compression stroke
> In petrol engine, the mixture is compressed upto about 1/8th to 1/12th of its original size.
> In diesel engine, only air is compressed upto about 1/14th to 1/25th of its original size.

Expansion stroke
> In petrol engine, the air and fuel mixture is ignited using a spark plug and burns expanding and forcing the piston down.
> In diesel engine, fuel is injected at a high pressure into the hot, compressed air in the cylinder, causing it to burn and force the piston down. No spark is required.

Exhause stroke
> In both petrol and diesel engines, the burned mixture of air and fuel is pushed out of the cylinder by the rising piston.

A diesel engine is also known as a "compression ignition" engine. Since the air is compressed to very high pressure raising its temperature and then diesel is injected in a very fine spray which causes the diesel to ignite and explode. Whereas a petrol engine is known as a "spark ignition" engine. Since a spark plug is required to ignite the mixture of petrol and air in the combustion chamber.

Diesel engine


Petrol engine


Lets also note down more differences of the same


  • A diesel engine is more easily turbocharged than a petrol engine. A petrol engine cannot be easily turbocharged due to the fact that if the compression ratio and the pressure in the cylinder is to high during the inlet stroke, the mixture starts to burn to soon, while the piston is on its way up. The diesel engine has no fuel in the cylinder, thus letting the turbocharger suck as much air as it can without creating any problems. (A turbo charger is a simple air compressor which compresses air in the combustion chamber for burning). Some diesel engines also have an intercooler which helps in blowing cold and oxygen rich air in the combustion chamber.

  • Electronic engine management not necessary in diesel engines. Some modern diesel engines are gaining electronically controlled injection pumps, but the vast majority of them out there have purely mechanical pumps. In fact no electricity is required to make a diesel engine run, except for a simple fuel cut off solenoid so that you can switch the thing off! If your alternator stops working, then you’re gonna get home in a diesel. This also means that a diesel engine does not have any ignition breakers, ignition coils, distributors and ignition wires to go bad. So a diesel engine should start no matter if it is dry or rainy or wet.

  • Petrol destroys lubrication and burns the engine whereas diesel doesnt. So a diesel engine would last longer than a petrol engine.

  • Petrol engines are lighter than diesel engines.

  • Diesel engines have higher torque than petrol engines. What does this mean? Well, this means that a diesel engine would pull heavy loads easily than a petrol engine. Though the pickup of a petrol engine would be much more than that of a diesel engine, the diesel engine would be steady and carry heavier loads to longer distances.

  • Diesel engines have better fuel efficiency as compared to petrol due to the fact that they have higher compression ratio.

  • Diesel engines dont need an ignition system, which reduces their complexity. But they are more noisy and may require frequent maintenance as compared to petrol engines. Also they are more durable.

  • Diesel engines may also need glow plugs in extreme cold conditions which heat up the cylinder so that a cold engine can start easily.

  • And now the most important part, fuel economy. Diesel wins in both ways. Diesel engines give better mileage than petrol engines and In india diesel is much cheaper than petrol. So running on diesel would make you go farther at a lower cost than running on petrol.



Even after writing all this, i am still undecided where to go. Should i risk taking a diesel engine hoping that the maintenance costs would be bearable. Well, lets c what happens...

Tuesday, October 17, 2006

Reverse Proxy using squid

what is proxy server caching? hmm... lets start with what apache or any other web server does. Whenever you send a request to apache, the request (whether static or dynamic) is processed. The appropriate file is located in the file system and, the content type is identified and data is then streamed from the file to the web and hence to the browser. This is what the apache does. So where does proxy server come in picture? Proxy servers like squid are set up at the gateway level in cyber cafes or large companies. The proxy server caches web content in its internal cache and whenever a request comes to the proxy server, the server matches the modified time of the web content with that at the server, and if the time is same, the content is served from the proxy cache, else the content is fetched from the remote server and served and cached for future purposes.

So, now, what is reverse proxy caching? Reverse proxy is something which is installed in the neighbourhood of a web server. All incoming traffic to the web server is passed through the reverse proxy server. This reduces the load on a busy server by using a web cache between the server and the internet.

Following benefits are derived by deploying reverse proxy servers alongside web servers:

1. increase capacity of existing servers and prevent purchase of new servers.
2. static content is easily cached at the proxy server level, leaving the web server to handle dynamic content.
3. Increase response time of any web request.
4. proxy server acts like an additional layer of defence against hacking.
5. Load balancing: reverse proxy can be used to distribute load on several web servers.
6. Compression: web content can be optimized and compressed to speed up download times.

A reverse proxy server intercepts requests to the Web server and responds to the request out of a store of cached pages. Dynamic web content cannot be cached. Reverse proxy caches static pages / images based on HTTP header tags that are returned from the web page. Important HTTP header tags are:

Last-Modified -> when was the page last modified
Expires -> when would the page expire so that it can be removed from proxy server cache
Cache-control -> should the page be cached
Pragma -> similar to Cache-control, deciding factor whether the page should be cached or not

Here is what i did to install squid:

>> download the squid source gz file.
>> tar -xvzf squid-2.6.STABLE4.tar.gz - creates a directory squid-2.6.STABLE4
>> cd squid-2.6.STABLE4
>> ./configure --disable-internal-dns - makes squid use the /etc/hosts file for dns lookup.
>> make - compile the files
>> make install (as root) - copies the compiled files to /usr/local/squid
>> vi /usr/local/squid/etc/squid.conf
>> make the following changes. The configuration file format has been changed in squid 2.6. I am putting the new configuration settings here. Older directives of httpd_accel_* have been depricated.

http_port 80 vhost
socket address where squid listens to httpd client requests. Default is 3128 (for proxy server). Various options can be put after the port number. Like
transparent : support for transparent proxies
vhost : accelerator using vhost directive
vport : accelerator with IP virtual host support
defaultsite= : main website name for accelerators
protocol= : protocol to reconstruct accelerated requests with. Default is httpd.
no-connection-auth : prevent forwarding of microsoft connection oriented authentication
tproxy : support for linux TPROXY for spoofing outgoing connections using the client IP address


cache_peer [options]

for apache running on localhost on port 81, the configuration for reverse proxy - cache_peer directive would be

cache_peer localhost parent 81 0 originserver
hostname : cache peer to which connection has to be established type : how cache peer is treaded (as parent, sibiling or multicast)
parent -> the child cache will forward requests to its parent cache. If the parent does not hold the requested object, it will forward the request on behalf of the child.
sibling -> a peer may only request objects already held in the cache. a sibling cannot forward cache misses on behalf of the peer.
multicast -> multicast packet is from one machine to one or more.
proxy port : port no where cache listens to the peer requests
icp port : used for querying neighbour caches about objects
options : lots of options available like
proxy-only -> objects fetched from this cache should not be saved locally
weight=n -> specify weight of parent
round-robin -> define a set of parents to be used in a round robin way.
weighted-round-robin -> define a set of parents to be used in a round robin way, frequency of each parent being based on the round trip time.
originserver -> contact this parent as a origin server. used for accelerator setups

Thats it, just start your apache and squid and everything should run fine.
Hope this helps...

Source : http://www.visolve.com/squid/whitepapers/reverseproxy.php with some customizations to upgrade it for the new version.

Thursday, September 28, 2006

python

Yes python. No, I am not refering to the snake, I am refering to the programming language "python". OOPS!!! Sorry for the confusion.

Python is an interpreted, interactive and object oriented programming language. Often compared to perl, java, ruby etc. As per http://en.wikipedia.org/wiki/Python_programming_language, python was created by some dude named "Guido van Rossum" in 1990. It uses automatic memory management and is a High level language. Oooh.. And python is hot... Why?? Cause it has a very clean syntax and is easy to use and packs a lot of power inside it... Thats why, i think so... So lets get some tits and bits about python...

But before i start, just check out http://www.python.org, the official website of python software foundation the creators and maintainers of python.

The thing which will strike you at the start is the way indentation is important in python. Python groups sentenses on the basis of how it is indented. So i would write a for loop as follows


>>> arr = ['a1','b2','c3','d4','e5','f6'] # defining the array
>>> for x in arr: # starting the for loop
>>> print x # print the element and its length
>>> print len(x)
>>> print 'end' # print end the for loop. Indentation says for loop is over


The best thing i like about this is that developers would automatically indent their code making it good to look at - ummm beautiful may be the right word.

python has a nice set of string operators and regular expressions. You can create and iterate over a range very nicely, write functions, create stacks and queues, do file handling and exception handling. You have complete java style - try->catch level exception handling. And ofcourse you can create classes. Serialize and store objects in file very easily and then restore the objects later. Also there are lots of extensions available which would allow you to interact with the net, create threads, do data compression and decompression. control garbage collection.

Wooo, and the main thing is that all this is possible with very easy and clean syntax . I have seen small and large - in fact very large programs being written in python. And maybe sometime down in future python would replace perl for small programs.

You have got to try it out to see the power of python...

Wednesday, September 27, 2006

Your Love Element Is Metal

In love, you inspire and respect your partner.
For you, love is all about fusing together for one incredible life experience.

You attract others with wit and a bit of flash.
Your flirting style is defined by making others want and value you.

Greatness and optimism are the cornerstones of your love life.
You may let go too easily, but you never get weighed down by your past.

You connect best with: Earth

Avoid: Fire

You and another Metal element: will control and smother each other

Monday, September 25, 2006

where have i been??

Oh dear, one whole month gone, and there is just 1 blog - my contribution to the world of bloggers... Too bad "jayant"... Where have you been?? What have you been doing?? The world is moving on and you are still at the same place. Doing nothing, not even writing blogs...

My dear friends, actually there has been certain changes in my life... And i think, i had been a bit busy in these. Waise the start of this month was very eventful. We had a trip to agra. And for the first time in my life, i saw "Taj Mahal". You would say - "well buddy, whats there in a taj mahal. It is one of the wonders of the world, but still, it is just a monument made out of white marble. Isnt it?" And i would say, "yes yes, it is, it is. But you cannot guess the beauty of the monument just by looking at the images. You have to go and look at the monument to enjoy its beauty"....

To cut the long story short. The trip to agra was gud. We took our own cars and drove down to agra and came back in the same day. Went to see the "Taj Mahal" first thing in the morning and then saw the "Agra Fort". Then went to see the Fort at "Fatehpur Sikri". The Taj was gud, no doubt. Made out of white marbel and there are precious stones embedded in the marble. There are carvings and design patterns on the marble created using precious stones of red, orange, green and other colors. A lot of real hard work must have gone in creating the monument. Also take into account the fact that at the time when the taj was built, sophesticated instruments were not available . And the workers took around 22 years to build up the "Taj" - A monument of love created by the mughal emperor "Shah Jahan" for his beloved wife "Mumtaj Mahal" after her death.






Ok ok, so agreed, you were a bit busy in the starting of this month - around 3rd due to your trip to agra. What happened to the rest of the month buddy. Today is 26th. That is 23 days, without a blog. Hmmmmm, Hmmmmm, Aaaaaa, i have nothing to say. Ummm, i have a friend in orkut who keeps on writing lots of scraps and i had to reply her back. So it also took some of my precious time - you know..

Yes, of course!!! i know. And i had to plan my trip home. And ofcourse, another important thing - should i write.... umm maybe... Well, i have been getting lots of calls lately - lots of job offers... Though i keep on telling them that "i am not interested", but these companies and consultants dont leave me alone. And specially Yahoo!!! God, they have been after my life. But, for the time being i will continue with my current organization.

And ofcourse there were certain deadlines to meet in september. And we had some meetings over that and things were finalized. So, i got a bit engaged in those things. Still, saturdays and sundays - you had a bit of those free. You could have written something then.

Umm, yes, but i got busy... Hang on buddy, i will let you know everything after i come back from home. Oh, i will be going home on the 29th of september. And i am not getting 30th off, so i will be forced to take 1st and 2nd as leave increasing the count of leaves taken from 2 to 5. A loss of 3 days.

And i promice, will write a lot of details once i am back from home....

Till then....Just hang on...

Sunday, September 10, 2006

about love

The big question : what is love??

And the important fact for people reading this blog : i am NOT in love... This is just a thought which i wanted to pen down or maybe blog down...

So returning back to the big question. what is love? how would you define love. Is it the relation between a mother and a child, where the mother cares for the child and vice versa. Or is it the feeling between a brother and a sister. It is said that they share a bonding of "love" and care for each other. Or is it the friendship between two friends. Both friends depend on each other for something or other. They just feel good when they are together. Or is it the relation between a boyfriend and a girlfriend, where there is passion sometimes with and sometimes without commitment. Or is it the relation between a husband and a wife - a lifelong relationship where there is commitment, passion, understandings and minunderstandings, small and major fights, caring and dependency upon each other.

Lets explore each of these relations and try to define love out of these. From what i have seen, people generally tell "i love you" to either their boyfriend or girlfriend. Love in this sense symbolyses passion. Dont you think so?

Well lets start from the mother/father who loves her/his child. From the day the baby is born, parents feed and take care of the baby. Fulfill all his desires and try to make a man out of him. Give him education, food, shelter. Take care of him when he is sick. This, i think is love. Though "i love you" is rarely exchanged in this relation. Still, why does the parent take so much care of the child. Because, you feel that the child is your part. You are the creator of the child, and it is your responsibility. This feeling leads to a type of love and bonding. Where the child demands and the parent fulfills. There are fights and misunderstandings, but they are overcome, because you are bound to live together and care for each other....

The relation between a brother and a sister is, i feel somewhat similar to that between two very good childhood friends, except for the fact that the brother and sister have to live together. Again the "bonding" comes into picture. Which makes this relation stronger than that between two very good friends. There is love over here too, born out of the need to share thoughts and exchange ideas. You love and care for your sibling. What about 2 friends? what i feel is that the "love" between two friends is very selfless and fragile. Small fights can break up friendship unless there is good understanding between the friends. Friendships break because there is no "bond" between the friends. Well, friends are people with whom secrets can be shared, the secrets, which, otherwise may be considered "bad" in the family. Friends are people with whom you can form groups to accomplish something in life. You would never say "i love you" either to your sibling or your friend. Well, in some cases an "i love you" to a friend can break the friendship and hearts. So avoid it. Though sharing an "i love you" with your sibling would ofcourse matter and make the relation stronger.

Now lets come to the most important section of "i love you". The one between a boy friend and a girl friend. The boyfriend keeps on saying "i love you" to the girlfriend and vice versa. They generally become possessive of each other. There are cases where fights break out and there are broken hearts. Or one of them starts liking someone else and ditches the other. Whoa, yes there is a "love" between then but then again there is no "bonding" between them to keep the love, and hence them together. But of-course, there are lots of cases where boyfriend and girlfriend have a "love marriage" and live a very happy life.

Moving ahead lets come to the "love" between a husband and a wife. Well, there is commitment and the need to share the same life. To create a new life. There is a bonding between them that they should stay together - no matter what. Well, though in various cases, this bonding goes for a toss and they do separate. But we are dealing with ideal situations over here. Their life starts with passion and lust and moves to caring and understanding and then to parenthood and responsibilities. Do they love each other. Well, cant say. Newly married couples would say "i love you" maybe once every hour. And after ten years, the same couple would talk to each other maybe once in a day and that too for just 5-10 minutes. They still stay together and care for each other, but where has the "love" gone? Dont look like that at me. Even i dont have an answer to that. I am still unmarried and still have to experience all these things....

So from all the above relations what can be derived regarding the definition of love? Is love simply passion? NO... Is it caring and understanding? Well, maybe, but not completely. Then what is love?

I, myself am unsure about the definition. But just for the records i would simply pen down what i think love is. Or maybe what i believe, ideally love should be.

Love is an invisible bonding. A feeling of togetherness. Strengthened by trust, understanding and caring. Love is something which cannot be expressed, but only felt.

If you love someone, you would care for that person. You would be possessive about that person. You would care for him. And you would depend on him and want him to depend on you. But, in addition to being possessive, you will also need to set the person free and trust that the person does not go against your will. If you dont set him free, there would be suffocation in the relationship and both u and ur love would feel sad. And if the person goes against what you want him to do or does something wrong, you will need to understand why? If two people love each other their "love" should become stronger with each fight/misunderstanding they have. Since with each such situation, they would come closer and their understanding about each other will improve. And ideally there should be no place for "ego" in love.

Though there are people who become "deewana/deewani" in love. They have a sense of self sacrifice. To die/give up everything for someone they "love". To bear the pain and sorrow just to see that the one they "love" is happy. This, i believe is also "love".

I m thru... Let me know your ideas...

Wednesday, August 23, 2006

RAM disk in linux

A RAM disk is a portion of RAM which is being used as if it were a disk drive. RAM disks have fixed sizes, and act like regular disk partitions. Their access time is much faster for a RAM disk than for a real, physical disk. However, any data stored on a RAM disk is lost when the system is shut down or powered off. RAM disks can be a great place to store temporary data which needs to be accessed frequently.

For RAM disk to be accessed, the support for the same should be compiled with the linux kernel. As far as i remember Kernel 2.4.* and 2.6.* have RAM disk support compiled in it.

RedHat/Fedora creates 16 ram disks by default. Although they are not usable by default. The size of these ram disks is 4096K (4 MB).

To list available RAM disks use the command - ls -lh /dev/ram*.
To know default size of RAM disk use - dmesg | grep RAMDISK

As it can be seen, using the default configuration only 4 MB RAMDISK can be created. To create larger RAMDISKS you need to configure the kernel parameters so that larger RAMDISKS can be created. How ?? By simply passing the size of the RAMDISK as a parameter during booting of the kernel.

The kernel option for RAMDISK size is: ramdisk_size=<size in kb>.

All you have to do is type this at the boot prompt during booting. Or if you are using some boot loader like lilo or grub, you need to change the boot command in either lilo.conf or grub.conf. For example in grub.conf you would be having something like


# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You do not have a /boot partition. This means that
# all kernel and initrd paths are relative to /, eg.
# root (hd0,4)
# kernel /boot/vmlinuz-version ro root=/dev/hda5
# initrd /boot/initrd-version.img
#boot=/dev/hda
default=0
timeout=5
splashimage=(hd0,4)/boot/grub/splash.xpm.gz
hiddenmenu
title Fedora Core (2.6.11-1.1369_FC4)
root (hd0,4)
kernel /boot/vmlinuz-2.6.11-1.1369_FC4 ro root=LABEL=/1 ramdisk_size=512000 quiet
initrd /boot/initrd-2.6.11-1.1369_FC4.img
title Windoze XP
rootnoverify (hd0,1)
chainloader +1


The above configuration file would create ramdisks of size 512MB. There is an upper limit to the max size of RAMDISK that can be created and it is also controlled by the amount of available RAM. So if you have 512MB of RAM, you would not be able to create RAMDISKS of more than 512MB. But depending on the kernel configuration, if you have a 4GB RAM system, you may not be able to create RAMDISK of more than 1GB maybe. You will have to check this limit either with the kernel documents or by trying out different sizes at boot prompt.

Once the RAMDISK size has been configured, all that needs to be done is to create a file system on the RAMDISK and then mount the RAMDISK as a file system directory in linux.

To create an ext2fs file system, the following command is used :

mke2fs -m 0 /dev/ram0
The -m 0 option keeps mke2fs from reserving any space on the file system for the root user. This makes the complete ramdisk space available to any regular user.

To mount the ramdisk :


mkdir /mnt/RAMDISK
mount /dev/ram0 /mnt/RAMDISK


Run mount to check whether the RAMDISK has been mounted.
Now the RAMDISK can be used as a regular directory. You can read, write, delete and modify files on the RAMDISK as if you are working on a regular hard disk. Linux would handle it as if it were handling a regular directory on the disk. The difference between RAMDISK and normal DISK would be invisible to a regular user.

The only problem is that if the system is either rebooted or crashes. In that case, all data in the RAMDISK is lost. You will need to recreate the RAMDISK and redo all that has been done.

The benefit of using RAMDISk is that reads and writes ot the RAMDISK would be extremely fast, since everything is in RAM and not on the DISK. To prevent loss of data, it is advisable to keep a backup of data in RAMDISK on the local HDD.

The commands used to create the RAMDISK and loading of data in RAMDISK can be automated by issueing the command in the rc.local or some other startup script.

More details of effectively creating and using RAMDISKS can be obtained from the kernel documentation.

http://www.vanemery.com/Linux/Ramdisk/ramdisk-kerneldoc.txt

Monday, August 21, 2006

trip to kasauli + chail

I have been a bit busy and the blogger was really missing me... anyways, had gone for a trip to kasauli & chail (both are near to Shimla).

Well, initially we were planning to go to jaipur, but we found that due to rains the santuaries would be closed. Moreover, there might be lots of heat in jaipur. And we were planning to go on our bikes. Me on my bullet. So, this got dropped. Next we decided to go to some nearby hillstation. After a lot of research, we decided to visit kasauli and chail. Both are near to each other.

Again the plan of going there on bikes was unsuccessful because one of our group members had a leg injury and it was difficult for him to drive for that long on his bike. It was supposed to be a 6-7 hours/300 kms drive.

Kasauli is around 300 kms from delhi and all we have to do is catch the NH1 to chandigarh and from there to panchkula and then to kasauli/shimla/chail. There is a single road to shimla, on taking a left you reach kasauli and on taking a right you reach chail.

Chail is around 60 kms from kasauli. You have to go down to a small river and then there is a very steep climb up a hill via a narrow road surrounded by greenery and trees. Lovely place to drive through.




We left at around 3 in the morning, gathered at a friends house and then moved on from there in his car. We were able to get on the highway by around 5:30 after filling air and petrol in the car. The highway was good and the drive was great. After a very long time i was able to see the sun rise and we also saw 2 rainbows one above the another on the way.




We reached kasauli around 12 in the afternoon. And we were shocked to see the rates of hotels. We were unable to find anything below 700 for a two bed and nothing below 800 for a 4 bed set. Anyways after lots of research we finalized to stay at R Maidens' some nice hotel with a 4 bed big and decent room. Then had something to eat and went to sleep. Roamed about a bit in the evening and relaxed at night.




Well, the next day we left at around 11 am for chail. Had parathas on the way and enjoyed the hills and the cool and clean air. I was able to see lots of people on bikes and really missed my bullet. At chail, the two things that we visited were - worlds highest cricket pitch and a temple. All the time we were in the clouds. The temple was very peaceful. And the drive wonderful. We came back in the evening and then relaxed.

Next day we went to manki point at kasauli. It was the best place we visited. It is situated inside a military layout, so you could not take any electronic items to that place, neither click photos of the place. We had to leave everything including the our cells, cameras and locking keypad of car inside the car. Had to climb for about 500 meters on a 75 degree slope. On top of th e place, there is a helipad and near that there is a temple. It is a very small place. After reaching the top we were inside the clouds. All we could see was clouds above and below us.

The monkeys over there are very aggressive. During our climb downhill, one of the monkeys took all prasad that we had. Anyways, the visit was good. And the place was worth all the effort.

Later that day, we did some shopping and then relaxed. Next day we left kasauli around 12 pm and were in delhi at around 6:30 pm. Back to the city, heat, pollution and our everyday busy lives.

Saturday, August 05, 2006

mysql partitioning

Table partitioning is a concept which allows data to be stored in multiple locations on one or more disks and access to the data is through SQL queries. The way data is stored and retrieved is invisible to the end user.

Mysql allows the user to select the rules based on which data would be spread over multiple partitions in a table. Mysql supports horizontab partitioning whereby the rows of a table are spread across multiple locations. Support for vertical partitioning is not there. So using mysql partitioning, you cannot assign different columns to different physical partitions of a table.

Benefits of partitioning a table :
1. Being able to store more data in one table than can be held on a single disk or filesystem partition. Though current operating systems allow extremely huge files on the disk.
2. Data that loses its usefulness can often be easily be removed from the table by dropping the partition containing only that data. And adding of new data can be facilitated by adding a new partition specially for that data.
3. Some queries can be greatly optimized in virtue of the fact that data satisfying a given WHERE clause can be stored only on one or more partitions, thereby excluding any remaining partitions from the search. Data can also be re-organized to move more frequently accessed data to one partition.
4. Queries involving aggregate functions such as SUM() and COUNT() can easily be parallelized.
5. Greater query throughput can be achieved by spreading data seeks over multiple disks.

I had used partitioning with MYIASM tables and found out that they were very useful. The complete logic of how rows were divided and stored and how they need to be accessed was invisible to me. What happened when i created some partitions for the table is that the same number of .MYI and .MYD files were created. Though the table definition remained in the single .frm file. A separate .PAR file was created for the table which i think was being used to define the logic of how database was being partitioned.

Moreover, an insert on the table locks all the partitions for a small time that is, the time needed by mysql to decide in which partition the record should be put.

The logic using which a table can be partitioned are listed as below:

RANGE partitioning -> Here table partitions are defined based on a range of data to be stored in each partition. For example -

CREATE TABLE abc (
name VARCHAR(100) NOT NULL,
email VARCHAR(40),
dob DATE NOT NULL
)
PARTITION BY RANGE( YEAR(dob) ) (
PARTITION p0 VALUES LESS THAN (1960),
PARTITION p1 VALUES LESS THAN (1970),
PARTITION p2 VALUES LESS THAN (1980),
PARTITION p3 VALUES LESS THAN (1990),
PARTITION p4 VALUES LESS THAN MAXVALUE
);

This would create 5 partitions in the table abc. Partition p0 will contain records whose dob is from 0 to 1959, partition p1 will contain records whose dob is from 1960 to 1969 and so on. In case a row is entered whose dob cannot be accomodated in any of the partitions, an error is thrown and the data is not inserted in the table.

LIST partitioning -> Here table partitions are defined based on a list of data for each partition. Rows which satisfy a criteria list is inserted in that partition.

CREATE TABLE abcs (
name VARCHAR(100),
dob DATE NOT NULL DEFAULT '1979-01-01'
age INT
)
PARTITION BY LIST(age) (
PARTITION p0 VALUES IN (3,5,6,9,17),
PARTITION p1 VALUES IN (1,2,10,11,19,20),
PARTITION p2 VALUES IN (4,12,13,14,18),
PARTITION p3 VALUES IN (7,8,15,16)
);

This would create 4 partitions in the table abcs. Partition p0 would contain records whose age would be 3,5,6,9 or 17. Again if you try to insert a record whose dob is not in any of the partition list created, an error is thrown and the record is not inserted.

LINEAR HASH partitioning -> Here table data is evenly divided between all partitions using some simple functions. for example

CREATE TABLE abc (
name VARCHAR(100),
dob DATE NOT NULL DEFAULT '1970-01-01',
age INT
)
PARTITION BY HASH( YEAR(dob) )
PARTITIONS 4;

Here 4 partitions are created and data is distributed using the following formula
Partition number = MOD(YEAR(dob),number_of_partitions);
So since my date of birth is 1980, my record will be in partition number 0.

LINEAR HASH partitioning -> This is almost similar to hash partitioning except for the fact that the algorithm used to divide data is different. The syntax is also almost same. We use PARTITION BY LINEAR HASH instead of PARTITION BY HASH.

The algorithm used is :

Given an expression expr, the partition in which the record is stored when linear hashing is used is partition number N from among num partitions, where N is derived according to the following algorithm:

  • Find the next power of 2 greater than num. We call this value V; it can be calculated as:
    V = POWER(2, CEILING(LOG(2, num)))

  • Set N = F(column_list) & (V - 1).

  • While N >= num
    {
    Set V = CEIL(V / 2)
    Set N = N & (V - 1)
    }



The advantage in partitioning by linear hash is that the adding, dropping, merging, and splitting of partitions is made much faster, which can be beneficial when dealing with tables containing extremely large amounts of data. The disadvantage is that data is less likely to be evenly distributed between partitions as compared with the distribution obtained using regular hash partitioning.

KEY partitioning ->
Partitioning by key is similar to partitioning by hash, except that where hash partitioning employs a user-defined expression, the hashing function for key partitioning is supplied by the MySQL server. The syntax used is PARTITION BY KEY instead of PARTITION BY HASH.

In most of the cases either a primary key or an unique key is used to create partitions.

Mysql also supports sub partitioning whereby a partition can be divided into further sub partitions of similar type.

I think i am creating a very long blog for mysql partitioning. However there are a list of syntaxes available on the mysql site to alter, analyze, optimize, rebuild, checking and repairing partitions. Please check http://dev.mysql.com/doc/refman/5.1/en/partitioning.html. It will give a more detailed idea of whatever ranting i have done over here...

I will be signing off from here now. Next blog may or may not contain more info about partitions...

Anyways will keep blogggging...