Results

EE5903 (RTOS) Assignment 1: Implementing M/M/1 queue using POSIX message queue

Since I spent around 2-4 days in completing this assignment, I thought maybe someone might find this useful in the future. Its not just the code for this problem. I had to learn other features like timers, signals, fork, and (ofcourse) Linux message queue. I had used some of them before but this assignment helped me in understanding them deeper. And I definitely enjoyed doing this assignment.

Disclaimer: Venture in to this blog only if you are interested, else it may be boring.

Problem Definition
Use POSIX Message Queues on Linux
• Producer produces serial numbered messages with exponentially distributed inter-arrival time (avg. 1s)
• Consumer processes messages with an exponentially distributed processing time (avg. 0.8s)
• Producer & consumer log system time and message serial numbers
• Run the system for 300s
Process the logs to compute the following
• Message loss percentage
• Average number of messages in queue
• Average latency (including processing time)
Fraction of time with more than 10 messages in queue

Design
I didn’t do any specific design, but I had some idea on how to develop this step by step. I started by testing the message queue in a sequential program. The function producer puts messages to the queue and consumer takes it in specific intervals. Then I integrated random intervals to make the producers output exponentially distributed using random number generators, then I made it 2 separate processes using fork and later I added signals, etc. The output is stored in to a log file and later that is parsed using another program called log_processor.c. I would like to add the entire development story here, but that would take up the entire space. So, if any of you have any suggestions or queries, drop a comment.

Code
msg_q.c
log_processor.c

Note: I am not able to post code in blog page (so many formatting errors) and I am looking for various options to upload in some site and give the link here. Please let me know if anyone have any suggestions. Also, if anyone want to have a look at the code, please leave a comment.

Individual Code Snippets
  • Random numbers
  • Fork
fork() is something I always had difficulty in understanding. The idea of same code running in parallel was a bit difficult for me to understand. The key point to remember here is, once the call fork is made, there are 2 instances of the program running and both will run the same code. So, in order to make them both do different things, we have to know which is parent and which is child and that's where the chpid comes in. If the chpid has a value greater than 0, we are in parent process. If it is 0, we are in child. And if it is less than 0, fork failed. simple, right? We can use an if(chpid > 0) condition and call different functions. Also, both are different processes and child or parent doesn't share any memory/variables, the advantage is, you can use for both, disadvantage, have to be careful when you use the variables.

  • Signals
  • Timers
One important point to remember here is, the function usleep() takes an input in microseconds and in some machines, it will not work for second resolution (for values more than 1000000). It may or may not work for values more than 1 second. Its always better to use values less than 100000 for usleep() and anything above that, split it to 2 and use sleep() and usleep(). The program below, I wrote to test whether it works in my machine. I found it was working, but in the final code, I used both usleep() and sleep().
LOG FILES
I am not putting the entire log files here. Just a small part.

1
302593147
1
2
303410285
0
3
304745777
0
4
305170614
0

Report
Here is the main part of the report I submitted. No fancy stuff, just the facts.

Output of log_processor.out file

Message lost percentage : 0.660066 %
Average Latency : 3.26471 seconds
Average number of messages in queue : 3.06954
Percentage of time with more than 10 msgs in q : 0.331126 %

Explanation

1. Since the producer sends the messages in a blocked state - it waits for the queue to be free, if its full - and also the queue size is almost infinite as compared to the number of messages we send, there is very less chance of a message being lost. However, since we run the simulation for a certain time, at the end of time, there may be some messages which are being processed at the consumer. That is the reason why we see a very small value for the percentage of message loss. If we run the test for a certain number of input messages, there won't be any message loss since the queue won't get full and also since we don't drop a message if the queue is full (blocking call).

2. Average latency is calculated by calculating the individual latencies and taking the average of them.

The implementation is an example of an M/M/1 queuing system.
In theory, the average latency of a message in a system is,
W = 1 / (service rate - arrival rate)
or
W = Waiting Time in Queue + Service Time
W = W.Q + S.T
W = (arrival rate) / (service rate) (service rate - arrival rate) + Service Time (0.8)

Arrival rate = 1/1 = 1 msg/sec
Service rate = 1/0.8 = 1.25 msg/sec

Avg Latency (from theory) = 4sec
Avg Latency (from implementation) = 3.264sec

Since the values are derived by statistical modeling of the system, a small variance will be present. Also, when the test is run for 600 seconds, the values are:

Message lost percentage : 0.34904 %
Average Latency : 4.85368 seconds
Average number of messages in queue : 4.58829
Percentage of time with more than 10 msgs in q : 14.1608 %

The test only will give a value which is approximately the theoretical value.

3. Average number of messages in the queue is calculated by calculating the average of the number of messages in the queue during instants after the producer puts a message in the queue and before consumer takes a message from queue.

Theoretical calculation:
Average number of customers in the system is,
L = arrival rate / (service rate - arrival rate)
L (from theory) = 4
L (from implementation) = 3.06954 ~ 3

In the test with 600sec, the value is around 4.

4. Fraction of time with more than 10 msgs in queue is calculated by finding the number of samples which had a message number greater than 10 and dividing it with the number of samples taken.
Percentage of time with more than 10 msgs in q : 0.331126 %

Details of Test machine
Linux Flavor : Fedora Core 7
Kernel : Ver. 2.6.21-1.3194.fc7
Compiler : gcc Ver. 4.1.2 20070502 (Red Hat 4.1.2-12)
VMware : VMware Server Ver. 2.0.0 Build 116503

Processor : Intel Core 2 T7200 @ 2.00GHz each
RAM : 2.00 GB
Make : Alienware Area-51, m9750

References
http://www.ecst.csuchico.edu/~beej/guide/ipc/mq.html

Back to College Days: Trip to Melaka, Malaysia

I was going nuts trying to crack my wireless protocols assignment when that mail popped up in my maibox. “Trip to Melaka, Organized by NUS”, anyone interested? I believe in a principle which goes like, “Never say No to friends”. That’s how it all began.
Day: February 28, 2009, Saturday
Time: 0630

No no, its not the time when I woke up to study, but it was the time we gathered in front of the sports hall (our gathering point) to start our trip. I had no idea what to expect or what exactly is this trip about and what is there is Melaka. For me, it’s all about spending time with my friends and taking a break from my hectic schedule. So I didn’t have any expectation about my first international trip except that I knew there will be one more county’s stamp in my passport. But it turned out to be one of the most memorable days in my life and I went through a lot of feelings I thought was lost forever - the feelings and colors of college days - it felt like being back in my undergrad days.

Just like a dream!

A beautiful Chinese Letter carved in a rock in a temple. I have no idea what this means!

Old drawings in the wall of a temple

Our lunch and dinner was fabulous.
There are 2 things I like for a meal.
1. A delicious meal, as usual
2. A good company to start digging in to the task
And this was one of those rare occasions when I had both. For both lunch and dinner, there were around 7-9 dishes, with chicken, crab, prawns, fish, shark, vegetables (I didn’t concentrate in this area much), and dessert. Also, I think they were authentic Malay dishes, but since all of us were Indians, we had not much choice to get clear idea about the names of the dishes. Even if there were some means to get to know the names of the dishes, I seriously doubt we would have done that, ‘cos we were all very busy ‘fighting’ across the table that there was no time to talk.

A busy Melakan Street.
Since the city is kind of an old city, the streets are narrow. The buildings were painted really colorfully and you don’t get the feeling of a city.

In front of the Church of Christ

Who we are? (Click on the photo to read)
From Right
My House Owner : Aniket (My Housemate and a very dear friend)
My Financer : Ashwin (Friends for past 9 years)
Would be Dr. : Karthik (A new guy I met on the trip day, doing PhD in NUS)
Possible Roommate : Sampath (A possible future roommate)
Shashi Sir : Robin (A great friend who is my current roommate)
From Singapore : Girish (He is from Singapore itself)
Classified : Classified (;))
The Trouble Maker : Srijith (Karakku company)
Me : Me (You put your definition in the comment section)

A busy day in the Museum

Stairs to the courtyard or heaven?

F.R.I.E.N.D.S

Melakan Street: A view from the Top

An Ancient church in Melaka
This church - I think the name is St. Francis Chruch - is located on top of a small hill from where you get a really gorgeous view. It really was fun and soothing being there, enjoying the wind, and the songs of the native singers and there were several artists doing live drawing/paintings.

The Native Singers

A View from the Church

Tea Time: A Coffee shop in Melaka

Yeah, The Trouble Makers
No intro needed I guess. We went around looking for a coffee shop and had some fun and got lost from the group. We had to roam around for a while to find the group. Since it was another country, our mobiles didn’t work, we went back to the place where we started and the group was gone. Our choices were to go back to Singapore on our own - The Red Bus - or to go to the police station and ask for help. Before choosing from the above options, we asked some of the pedestrians for their mobile and called one of our friends and somehow got back to bus. And we heard some ‘sweet’ words from the ‘nice’ people who were waiting for us. The poor tour guide went around looking for us and came back exhausted to report he couldn’t find us, and we were there. Since he was a very good person, he didn’t tell us anything.


The End: The GSS group from NUS
I would like to thank all of my friends and whoever else who made that trip possible, because of whom I had one of the most memorable days in my life.
More Photos @ http://picasaweb.google.com/gssmalacca/TripToMelakaMalaysiaFromGSSNUSByManuIgnatius?#

ps: There are a lot more things I would love to write about this trip, but I am too sleepy now. Also, this was supposed to be a cultural trip.

Alienware Area-15 m9750 - A Dream Comes True

Just when you thought it couldn't get any better... we bring you this!
Most of you might be wondering what this things is, something related to aliens, from another world? You are almost right, ‘cos there is almost nothing in this earth which can compete with this bad boy! It’s the most recent edition to my gadget collection, and the most priced one too, my new laptop. I cannot entirely say its brand new, ‘cos I’ve had this baby for around a month.

From a Bad Start
I would say, I added this buddy to my collection at a really bad time, at the beginning of the first semester of my Masters. I had some problems getting right ordering and support and also with the factory installed software and drivers. Also I still haven’t got time to play around with it, the way I want to. But I can’t wait to write this entry for so long. ‘Cos its one of my dreams coming true.

My Alienware Area-51 m9750

The Spec Stuff
You can get a usual round of review from any review site in net, but I am going to present the details of my system. In short, it’s awesome. Better than the best machine I have seen and used so far. (that includes desktops also, since I haven’t used any desktops with the Ge-Force 200 series GPUs). Armed with GeForce 8700m GT GPU - “the world's first Microsoft DirectX®10 supported high performance enthusiast gaming notebook GUP”, after which any serious gamer started to think about gaming on a laptop, with a core clock speed of 625MHz, memory clock of 800MHz, dedicated 512MB video memory and a total of around 1269MB (including ~700+MB shared memory), 32 stream processors, and a 128bit memory interface, this baby flies with almost all the latest games. Other specs of this machine includes a Core 2 Duo T7200 @ 2.0 GHz processor, 2GB DDR2, a 17” LCD Display with a resolution of 1920x1200 @ 60Hz, 5.1 surround speakers with sub woofer, 160GB HDD, blah blah blah...

The combination of the big display and the 8700m GPU give you the best imaging quality you have ecer experienced. With digital vibrance technology, I have realized that images were this colorful and vibrant. And with that high resolution, you mostly never have to use the scroll function, since a 100% zoomed MS word page will fit in one screen.

As some of you may have already guessed, this is not the newest laptop or the best configuration available in the market. I wanted to have an SLi with the 9M series, a 4Gig RAM, an SSD HDD etc, but I had constraints on my ‘pocket size’.

I have included screenshot of the System requirements Lab Analysis report of Tomb Raider 8 and Halo 2 here. The recommended requirements for Tomb Raider 8 are shown failed ‘cos they expect to have a CPU with 2.2GHz speed and also a GPU which is Ge-Force 9800GTX/ATI HD 4800 or higher. For a DirectX 9 based, previous generation game like Halo 2, this system passes both the tests.


Gaming Gaming Gaming! - “Seeing is Believing”
As I have stated earlier, I haven’t got enough time to play around with this baby. But I somehow managed to test it with Crysis and Tomb Raider 8. I don’t want to explain the experience. Just see it for yourself.




You could see the expression in Lara’s face. Gaming in this machine is not just fun or entertainment, but it’s an experience. [You may have already guessed it, I am waiting to finish Tomb Raider 8 and write an entry on it ;-)]

Best Machine (with some glitches), Worst Support
Event though the laptop is the best of its class, there is no excuse for the continuous bad support (or lack of support) I am receiving from Alienware. I had to wait for more than 2 months to get my order shipped. Of course it was an international order. Even then, whenever I call them, I got overall really bad experience. (Exceptions are there).

I am having trouble with the integrated webcam. When I received the system, the cam was working fine for 2-3 days. Now it’s not at all showing anything other than a dark screen. I have tried updating my driver. No result. I found that others also had the same experience from some forums, but no idea how to rectify it. I have already sent 3 support request mails to the Alienware team, but no replies. Also, my wireless adapter stops abruptly sometime. The problem used to occur frequently in the beginning, but after driver updates, its working fine.

From my experience, I seriously urge anyone who is thinking to go with an Alienware machine to reconsider your decision, if support is of utmost importance to you.

The Good the Bad and the Ugly
Pros
- Amazing graphics, fast gaming performance
- Awesome screen resolution and large display
- Cool, Solid Design
- Best laptop in its class and worth every penny you spend

Cons
- Weight = Min 3.5Kg/8lbs, Portability = 0, Not for travelers.
- Pricing. I went for the relatively low configuration. But it cost me $1716 + my long distance calling charges for tracking the laptop updates.
- Bad Support

Summary - “Neighbor’s Envy, Owners Pride - Onida”
This machine is not for the ‘casual, light hearted’ people, who’s concept of a laptop is ‘just’ another portable electronic gadget. This is the real thing, custom built for enthusiasts or gadget geeks who are performance hungry, who likes to stay in the bleeding edge of technology. Its not all about performance alone, but about the brand also. Most of the people whom I have come across have no idea what Alienware means or which company made this laptop. But for the few who know what it means to own an Alienware machine, I have seen the mixture of respect and envy in their eyes at the mere mention of the term Alienware or when they see that blue eyed alien shining on the lid of my laptop. I can read their thoughts from their expression - which is something I used to have before, “I wish…”

Links and References
http://www.alienware.com/products/area-51-m9750-notebook.aspx?SysCode=PC-LT-AREA51M9750&SubCode=SKU-DEFAULT
http://www.notebookreview.com/default.asp?newsID=3840
http://www.anandtech.com/mobile/showdoc.aspx?i=3070
http://laptoplogic.com/best-gaming-laptops/
http://www.nvidia.com/object/geforce_8700m.html


Valentine’s Day in Singapore

This time it’s a Saturday and in the even me and my friends planned a small outing since its really pathetic to spent a valentine’s day, idle at home. The place is called, Marina Barrage, which is a dam in Singapore built across the Marina Channel between the reclaimed lands of Marina East and Marina South. Since we all stayed at different places, we decided to get together at the Marina Bay MRT (Mass Rapid Transit which is the domestic Train service in Singapore) by 5:15 pm.

I got in to the MRT by around 4:30pm. What more can I say, love was in the air. Everywhere you looked, you could see happy couples chatting or hugging or kissing. Most of them had bouquets or gifts or heart shaped symbols with them. I noticed a young couple in particular. They entered from the next station after I boarded the MRT. They were young and really vibrant. They were so happy that soon after the moment they entered the train, they became the focus of most of our passenger. The girl was slender and thin, resembled an angel from fairy tales and anyone who looked at her could easily say that she was in some other world. She firmly held the guys hand as it was her life source. I could read the pride in the guys face, like the king of the world. The atmosphere was so full of love. I felt happy for them. I don’t know any details of anyone in that train, but the way I felt after spending some time in that atmosphere was really different.

Suddenly I thought about a news link my cousin sent me today morning. The news was related to a group opposing Valentine’s day celebrations in India. I discussed it with my friends when I met them and I really felt sad/sorry for the group. In other words, in India, Valentine's Day is not the day to celebrate your love, but its the day to stop people from being happy for their love and conducting protests related to it. The way I see it, a person can have his/her own views and believes and practice them (as long as it doesn’t interfere with other people’s believes) and he/she can advertise about their views. And they can advice others to adopt your views. But the moment when it reaches the point when a person forces others to follow some believes, that’s the end of democracy or freedom. Valentine’s is the day when you can celebrate your love. But what if that right is forcefully denied? Also, I feel, the more you try to keep things wrapped up, the more others want to have it.

Anyway, by the time I met my friends, I left behind all these thoughts and worries and we all spend some quality time in Marina Barrage. You can have an amazing view of Singapore’s skyline and since it was a Saturday and a special day, so many people were there and the place was really lively. I am attaching some photos here.

Marina Barrage

A view from the top of Marina Barrage

Happy moments...

Singapore Gaint Flyer

ps: The views I have expressed here are my personal views only.

More Links
http://www.hindu.com/thehindu/holnus/001200902141411.htm
http://www.hindu.com/2009/02/14/stories/2009021455541200.htm
http://www.expressindia.com/latest-news/Girl-power-Show-Ram-Sene-whos-the-boss/423115/
http://ibnlive.in.com/news/ram-sene-warns-against-celebrating-valentines-day/84398-3.html
http://www.hindu.com/2009/01/27/stories/2009012759890100.htm

I reached Singapore (20 days back)

Yeah, its been exactly 20 days since I reached Singapore. Its not that I was waiting for Jan 26 to write this blog, its just so happened that I was not able to write it any sooner.
Yeah, I landed here on Jan 6th morning. I was expecting my friend. He came by the time I had some currency changed and we took a taxi to the place where I was going to stay. It was a nice ride, as the Changi airport was in one side of the country and the place where I was going to stay was on the other side of the country. My friend explained the places while we were going through there. This place really is clean. And almost all the places you look, you can see the country growing upwards. Lots of sky scrapers.
In 20 -30 minutes, I reached the place where I stay - yes, that’s the time it takes for you to travel from one end of Singapore to the other end. My apartment is on the 21st floor of a building, and it is not every day, till now, that you will find yourself in the 21st floor of a building. The view is awesome.

View from My Place

By the time I started settling down, another of my friend who is my roommate came. We are both from Kerala and we had some initial talks and we concluded that our first priorities are to bath, get something to eat, get a mobile connection and call home and open a bank account if possible.
We bathed and dressed and got out to the nearest mall. The weather is almost the same as that of in Kerala, humid and warm. We found a place to get a tea/coffee and then started looking for a mobile shop. From our friends we knew that SingTel is the service provider we had to look for. I really was worried about how much time will it take for the connection to get activated as I had several experiences from India. We found a SingTel shop. Within 10-15 minutes, me and my friend was calling home to give the new number and updating other details. The process was very simple.
The next thing for us was to open a bank account. We knew the names of the banks we had to look for, POSB (Post Office and Savings Bank) or DBS (Development Bank of Singapore). I didn’t want to do this on the first day of our arrival since I was really tired and opening a bank account requires so many formalities and all. But to our surprise, we finished all the formalities and I had a bank account, with ATM card and internet banking within 20minutes.
Here are some facts about Singapore. Everything about Singapore is EFFICIENT and CLEAN. There is no ethnic group as a Singaporean, and the ethnic groups here are Chinese, Indians (8%), Malay and Eurasians. Out of the whole population, around 25% are foreigners. Since there are so many familiar Indian faces, you won’t really feel that you are in a foreign country. As compared to India, cost of travel and living are high here. But the standards are equally high here.

Roads in Singapore – View from a sky pass

The next day, we went to university and registered. And so we officially became students in National University of Singapore. This time we didn’t even have to go to the embassy to get our student passes, they were there in the university and we just had to go and collect them. By the time I completed my registration, I had made some friends here and one of my best friends was here on transit. We all had a nice time. Since Singapore is a small place, it will take only around 3-4 days for you to explore the whole place.
I think I have visited almost all tourist places in Singapore, except for the ones which require entry passes, ‘cos they are really costly. I have been to Little India - its small India, you’ll really fell like you have reached India and I met some mallu people there, China Town - since the Chinese new year was due, that place was awesome, Sentosa - An island theme park, Clarke Quay, Raffles Place - The place where there is a giant Mer-lion, Chinese/Japanese Garden - very near to the place I stay etc etc. I even made it to the republic day celebrations here in the Indian embassy today. It was nicer than most of the celebrations happening in our places.
I want to write a blog about every single one of those expeditions and my experiences in singapore. I hope I will be able to make it. Since the classes have already started, I have lots and lots to study and work on. Still I am pretty sure that I will find time to update about my experiences here to bug my readers…
Here are some photos..


Chinese/Japanese Garden

China Town

Underwater World - Sentosa

Raffles Place - Merlion: With my friends

Near City Hall

Gaint Wheel near the Mer-lion Statue