My Experiments with OpenSource Kumar Abhishek's Weblog

Sunday Dec 20, 2009

I was a little curious to find out how my program gets executed. In order to find that out, I decided to write a simple c program which is here:



 #include <stdio.h>
int main()
{
    sleep(30);
    printf("Just testing an application!");
}



I have kept the sleep(30) in the beginning of the program so as to give me time to execute the DTrace script, about which I will be talking a little later.


Now i complied it with Sun Compiler and GCC



kumar@myosbox:~/Desktop/Demos$ suncc -o sunCCOutput simplec.c


kumar@myosbox:~/Desktop/Demos$ gcc -o gccOutput simplec.c



Now I wrote a simple DTrace script using the pid provider in order to figure out how printf is implemented (execution detail - functions which get invoked when printf function is called) in these compilers. The dtrace script is below:



pid$1::$2:entry
{
        self->trace = 1;
}

pid$1::$2:return
/self->trace/
{
        self->trace = 0;
}

pid$1:::entry,
pid$1:::return
/self->trace/
{
}



Now it was the time to execute this script and compare the outputs. I am going to redirect the output of this script into two text files (sunCCOutput.txt and gccOutput.txt).



kumar@myosbox:~/Desktop/Demos$ ./sunCCOutput 
kumar@myosbox:~/Desktop/Demos$ pfexec dtrace -F -s pid.d `pgrep sunCCOutput` printf > SunCCOutput.txt
dtrace: script 'pid.d' matched 6712 probes
kumar@myosbox:~/Desktop/Demos$ ./gccOutput
kumar@myosbox:~/Desktop/Demos$ pfexec dtrace -F -s pid.d `pgrep gccOutput` printf > gccOutput.txt
dtrace: script 'pid.d' matched 6714 probes



Now, the content of the file SunCCOutput.txt is as follows:



CPU FUNCTION                                 
1 -> printf
1 -> _setorientation
1 <- _setorientation
1 -> _ndoprnt
1 -> _findbuf
1 -> isatty
1 -> ___errno
1 <- ___errno
1 -> ioctl
1 <- ioctl
1 <- isatty
1 -> _setbufend
1 -> getxfdat
1 <- getxfdat
1 -> isseekable
1 -> ___errno
1 <- ___errno
1 -> fstat64
1 <- fstat64
1 -> ___errno
1 <- ___errno
1 <- isseekable
1 <- _setbufend
1 <- _findbuf
1 -> _realbufend
1 -> getxfdat
1 <- getxfdat
1 <- _realbufend
1 -> memcpy
1 <- memmove
1 <- memcpy
1 -> memchr
1 <- memchr
1 -> ferror
1 <- ferror
1 <- _ndoprnt
1 -> ferror
1 <- ferror


Contents of the file gccOutput.txt is as follows:



CPU FUNCTION                                 
1 -> printf
1 -> _setorientation
1 <- _setorientation
1 -> _ndoprnt
1 -> _findbuf
1 -> isatty
1 -> ___errno
1 <- ___errno
1 -> ioctl
1 <- ioctl
1 <- isatty
1 -> _setbufend
1 -> getxfdat
1 <- getxfdat
1 -> isseekable
1 -> ___errno
1 <- ___errno
1 -> fstat64
1 <- fstat64
1 -> ___errno
1 <- ___errno
1 <- isseekable
1 <- _setbufend
1 <- _findbuf
1 -> _realbufend
1 -> getxfdat
1 <- getxfdat
1 <- _realbufend
1 -> memcpy
1 <- memmove
1 <- memcpy
1 -> memchr
1 <- memchr
1 -> ferror
1 <- ferror
1 <- _ndoprnt
1 -> ferror
1 <- ferror

So you can see that there is no difference between gcc and suncc when if comes to implement the printf function. But its is so interesting to see that there are 19 function calls made everytime I use a printf in my c program! WOW! ;) I wonder if I could know it this easily if there was no Dtrace!

Friday Dec 11, 2009

You can do some crazy stuff with OpenSolaris and ZFS! Here is my crazy deal. Lets create a ZFS storage pool such that we have 2 Pen drives of 2 GB each and lets use it to save on big file of 3.5 GB (read store a nice DVD quality movie on two 2GB pendrives :P )


You will need two things for this:


1. Install OpenSolaris


2. Get two or more 2 GB (or of whatever size) pen drives / USB sticks (I do not have  2 pen drives with me so I will use one pen drive and one file to act like a pen drive. Process remains the same)


Step 1: Find out the device ID of your pen drive:



root@opensolaris:~# format -e
Searching for disks...done


AVAILABLE DISK SELECTIONS:
       0. c7d0 <DEFAULT cyl 3271 alt 2 hd 255 sec 63>
          /pci@0,0/pci-ide@1,1/ide@0/cmdk@0,0
       1. c9t0d0 <Generic-Flash Disk-8.07-1.87GB>
          /pci@0,0/pci8086,265c@b/storage@1/disk@0,0
Specify disk (enter its number):



In this case, the disk 0 is my hard disk, and 1 with device ID c9t0d0 is the USB stick. If I had two pen drives I would have had one more entry. However, I am going to create a new file of 2 GB under the name disk1 and use it.


Step 2: Create a new zpool on these devices. If you are using many multiple pen drives then instead of /root/disk2 use the device ID of the devices.



root@opensolaris:~# zpool create randomZpool c9t0d0 /root/disk2
root@opensolaris:~# zpool status -v
  pool: randomZpool
 state: ONLINE
 scrub: none requested
config:

    NAME           STATE     READ WRITE CKSUM
    randomZpool    ONLINE       0     0     0
      c9t0d0       ONLINE       0     0     0
      /root/disk2  ONLINE       0     0     0

errors: No known data errors

  pool: rpool
 state: ONLINE
 scrub: none requested
config:

    NAME        STATE     READ WRITE CKSUM
    rpool       ONLINE       0     0     0
      c7d0s0    ONLINE       0     0     0

errors: No known data errors



 Step 3: Create a ZFS filesystem on the storage pool



root@opensolaris:~# zfs list | grep randomZpool
randomZpool               101K  3.77G    19K  /randomZpool
randomZpool/dummy          19K  3.77G    19K  /randomZpool/dummy



Now you can see, that I have a ZFS filesystem of 3.77GB under the name randomZpool/dummy. Now let us define a mount point for the same.


Step 4: Define a mountpoint for the ZFS Filesystem.


root@opensolaris:~# zfs set mountpoint=/export/movies randomZpool/dummy
root@opensolaris:~# df -h /export/movies
Filesystem            Size  Used Avail Use% Mounted on
randomZpool/dummy     3.8G   19K  3.8G   1% /export/movies

 Now you have the backup of your 3.5 GB movie file on two pen drives :)


How you can use this small arrangement to do much bigger (and crazier) stuff is limited only by your creativity ;)


Happy hacking to all!



Sunday Dec 06, 2009

FOSS.IN 2009 was pinnacle of geekfests and it was after a long time that I saw so many open source fanatics under one roof!! Thanks to Bangalore OpenSolaris User Group (specially Sriram Narayanan and Anil Gulecha) OpenSolaris platform was successful beyond expectations in making hackers heads turn!



Sriram explaining stuff about OpenSolaris to interested participants of FOSS.IN


Everyone was so impressed with our demos based on ZFS, DTrace and Crossbow that I literally lost the count of number of times I heard phrases like "That is so cooool!" Even though we managed to keep just a table and two laptops (one was Sriram's personal laptop and the other one was mine :P ) people kept flocking to us while we demonstrated our simple hacks on OpenSolaris 2009.06.


On the last day, thanks to Joe George from Sun IEC, Bangalore, we managed to get some OpenSolaris T-Shirts and it was a riot! We had around 50 T-shirts and we had kept a condition that anyone who wants a T-Shirt would have to compete an assignment based on either ZFS, DTrace, Crossbow or Zones and we gave different sets of assignments to every participants. People were allowed to use man pages and google and it became such an interesting game that we had a long queue of people waiting for their turn to try their hands out at it.Within 5 hours all our T-Shirts were gone!


Me giving our first winner the opensolaris t-shirt


Me giving a OpenSolaris T-Shirt to our first winner


The most interesting bit happened when one of the participants (who said that he is feeling really out of place because he was very new to the world of computers) walked into our booth and asked if OpenSolaris has got something to do with solar energy. After I had a 15 mins chat, he got so interested and excited that he said even he would like to try his hand at OpenSolaris and by the end of the day, he won a T-Shirt by completing his assignment of creating a ZFS snapshot, deleting the Download folder and rolling back!


One guy trying out his assignment to win Opensolaris t-shirt while others listen to Sriram


One of the participants using my laptop to complete his assignments while others listen are taking their assignments from Sriram


Foss.in


Keynote from Philip Tellis of Yahoo! in FOSS.IN 


A few GNU skeptics who walked to us commenting on the CDDL were sent back satisfied by examples like Belenix and Nexenta. Over all, it was a great event and we learned many new lessons too! I hope hackers who drool on cool technologies will continue to fall in love with OpenSolaris!



Sun Cluster is one of the best things Solaris has! Cluster engineering group just came out with the new version of Sun Cluster 3.2 11/09 which is now available! Some of the exciting new development Solaris Cluster 3.2 11/09 has is tons of improvements in infrastructure features, some new features in Scalable services and of course better support for MySQL replication in Geographic edition. New deployment options for Oracle DB and RAC is also a feature to look out for in this release.


 Read more about it on Sun Cluster Oasis - http://blogs.sun.com/SC/entry/solaris_cluster_3_2_11


Wednesday Jul 08, 2009

OpenSolaris has been a hot topic in India for quite some time now and in the month of July its going to be everywhere!! In the ongoing effort to take OpenSolaris to every hand in India, we have worked with Indian media and bundled OpenSolaris 2009.06 Live CD with 2 major IT magazines! Going even ahead of it we have created a 16 page exclusive booklet for OpenSolaris 2009.06 which has been bundled with Chip Magazine. So more than 120,000 readers in India would have a copy of something to give them a head start on OpenSolaris and a Live CD to play around with. :) A total of more than 250,000 Live Disks of OpenSolaris has hit Indian newsstands this month and I hope it would give a good push to our community in India.




Feel free to download the OpenSolaris booklet here and distribute if you want. It features new features of OpenSolaris 2009.06, Installation guide, guide to setup Web development and Java Development environment and develop an example project in each, and an interview of Glynn Foster . It also includes details on OpenSolaris communities and OSUM! Good work by the magazine team and our OpenSolaris people! I hope you enjoy reading it ;)

Tuesday Feb 24, 2009

Hello!! Its been more than 6 months since I made my last blog entry... Sorry for that as I was busy working with loads of stuff in Sun Clusters, OpenSolaris Marketing and in Campus Ambassador Program.. But now I am back with some interesting stuff...


Sun Tech Days happened at Hyderabad from 18th Feb to 20th Feb which was attended by many many people! Many legends including James Gosling were there for the show! Joe Hartley was there for the event on 20th Feb and I took this opportunity to catch up with him about developments on education, open source and technologies to look for! Joe gave us some insights on what the future of education might be in light of growing adoption of social networking services like OSUM and penetration of the network. With help from Vasudha who is our campus ambassador at Manipal University, we recorded this pool side talk :-) Here is the video:



It was very interesting to talk to Joe after an year of WWERC 2008 held at San Francisco where I got a chance to interview him on similar lines. Watch that video here!

Friday Jul 11, 2008

On 9th of July, 450 members of GLOSS got to experience one (or I should say two) of the most amazing things of our ages! It was the OpenSolaris in Second Life!



Thanks to Terri, GLOSS got a chance to be a part of the OpenSolaris Chat in second life and we got a VIP pass! You can see the chat presentation here.. Now that we have many technical restrictions in Second Life and also that we have some network issues at SASTRA, I decided to pull all the crowd into TIFAC CORE auditorium and do a live screencast of the event, so that everyone would get to experience the chat as well as ask question. My initial expection was a crowd of just (now it sounds "just" :P) 200 students but thanks to Anand, who offered help to get it arrange for the girls in Nirman Vihar audi also. In a very short notice, we got everything arranged, and before I could realize, I was coordinating a crowd of 450 students spread across two different auditoriums (something I was doing for the first time!)


My team was present in both the auditoriums and I was coordinating everything via my cell phone! And soon the chat started! The moment everyone in the audience heard Heidi welcome, they just couldn't stop being amazed! But unfortunetly it did not last long as the experimental sound systems which was employed, crashed :-(  So the chat was moved to Text mode... And you know how we students are.. :) The moment something went wrong, no one could let the opportunity to exchange some fun go :P But once the chat caught up flow, everyone was completely into the chat! I was explaing the text line by line to all the students in the audi.. And then came the part of the question and answer. Now who could let the chance of asking question to people like Tim Cramer, Stephen Hahn, David Comay and Glynn Foster! 


All this while I was in the Nirman Vihar auditorium, and then towards the end I switched to TIFAC audi! The moment I walked in, I was welcomed with so many question!! :) It was from every area of virtual worlds and OpenSolaris. IPS was the hot topic again in the discussion! By the time, the last set of students bid me goodnight (who eventually walked with me till my room) the time was 11:30 PM! I distributed OpenSolaris wrist bands to all the participants who stayed after 10 (and unfortunely this number was also so large that I almost exausted almost all the wrist bands I had)


Because the chat was scheduled at 8:00 PM local time, most of the students who attended the chat missed out on their dinner. I must appreciate their curiosity and desire to learn new stuff! Also any thanks to Anand and team would be less for helping me out with so many stuff! We at GLOSS never miss out of taking picutres of the events, but unfortunately this time I could not manage :( 


Everyone in the Sun SL team did a great job... Check out Terri's blog for the complete transcript of the OpenSolaris chat and also Angad's blog for the pictures.

Tuesday Jul 01, 2008

After almost a month long vacation, when college reopened, we at GLOSS could not wait to do something exciting!! And what could be more exciting than Open High Availability Clusters (OHAC). I attended a talk on OHAC by Tirthankar during my recent visit of Sun India Engineering Center at Bangalore. I was completely taken by the technology and I knew I am going to do something with it, the moment I get a chance. Anyways... the day I landed in college, I sat down to set up a one node cluster on my laptop! Million thanks to Tirthankar again, who spend almost whole of his Sunday with me over the phone helping me out in setting it up. I would be blogging how set up a one node cluster on Solaris SXDE some time very very soon.


Now about the talk! There was a decent audience of more than 40 students who came to attend the talk. I started the talk with playing the Big Bucks Bunny movie, which set up the mood of the audience and also allowed me to introduce them to Network.Com and from there pick up the topic of difference between grids and clusters.



 Then I moved to the slides and I explained the architecture of OHAC and details of its functioning. It was an engrossing session, as explaining the functioning of a cluster and concepts like Disk Fencing can get tricky :) But it was nice to see every one interacting and asking questions to me!




Then was the turn of the Demo.. something which I was very eager to show. For this demo, I had prepared a single node cluster on my laptop. I had a zone running on which we had a cluster resource name movie-rg registered. The cluster agent was basically written to start RealPlayer on cluster and in case of a failure, it would make it failover to a functioning node of the cluster. The experience of setting up the cluster and getting the agent to work was truely amazing! As I said, I would be blogging about it soon, so check back soon. Here are two screenshots which shows how cluster took care of availability


Cluster resource right now online on the zone


 Now when I reboot the zone, the cluster resource becomes online on the physical node



I will soon be doing one more follow up talk on OHAC where I would discuss how to setup clusters and write agents for OHAC! Once again... thanks to Tirthankar and Swathi for helping me out with OHAC!