Thursday, September 29, 2011

Java class to test whether a file is in copying state or ready state

The following Java utility class could be used to test whether a file is in Copying state or it has been copied to file system. The class uses java scanner class. An infinite loop is used and upon each check the thread goes to sleep for 10 seconds. When the copying is completed the loop breaks.



/**
 * 
 */
package com.bishal.Test;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

/**
 * @author bishal acharya
 * This class is used to test whether a file is in copy state
 *         or Ready state.
 */
public class CopyProgress {

    private boolean isFileReady(String filePath) {
        File file = new File(filePath);

        Scanner scanner;
        boolean isCopying = true;
        while (true) {
            try {
                scanner = new Scanner(file);
                isCopying = false;
            } catch (FileNotFoundException e) {
                System.out.println("File not found or is in copy State. ");
                sleepThread();
            }
            if (isCopying == false) {
                break;
            }
        }
        System.out.println("copy completed ::");
        return isCopying;
    }

    /**
     * sleep for 10 seconds
     */
    private static void sleepThread() {
        System.out.println("sleeping for 10 seconds");
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void main(String args[]) {
        CopyProgress cp = new CopyProgress();
        cp.isFileReady("C:\\Documents and Settings\\bacharya\\My Documents\\videos\\Se7en.avi");
    }
}





Check Output : The output for the project would be

File is in copy State.
sleeping for 10 seconds
File is in copy State.
sleeping for 10 seconds
File is in copy State.
sleeping for 10 seconds
File is in copy State.
sleeping for 10 seconds
File is in copy State.
sleeping for 10 seconds
File is in copy State.
sleeping for 10 seconds
File is in copy State.
sleeping for 10 seconds
File is in copy State.
sleeping for 10 seconds
File is in copy State.
sleeping for 10 seconds
copy completed ::

Tuesday, September 27, 2011

Scale Up vs Scale out vs Scale in

Scalability Types


Scale Up vs Scale out vs Scale in


The general understanding of scalability is that If a system does not denigrates in performance when load or data size on the system increases then it is called scalable system. This definition is quite acceptable. But, what if our business requirement change? Will the system be still of the same scale? This question might trigger a need to define scalability in another way.
If an application or system is able to cope up well not only when many users turn up or data size increases in the system but also when the business requirements changes then the system is called scalable system. Now this definition to scalability not only addresses the change in load to the system but also addresses the business requirements change. There might be other dimensions to consider like administrative measures, functional measures and come up with a truly scalable system.



Scale Up systems:


Scale up systems is also known as vertically scalable systems. The ability of systems to improve its performance when the resources are scaled vertically is known as scale up systems. The resources could be memory, disk capacity, bandwidth etc. These systems traditionally run on top of single server and could possibly enhance its performance when scaled vertically. Examples of these systems are traditional databases, web servers and traditional applications windows applications. Many of scale up systems are single threaded applications but can be multi Threaded too. The computation is centralized.


Scale In Systems:


The ability of systems to run multiple threads upon multi core machines is known as scale in systems. For eg. 10 instances of Mysql running on top of 10 core machine is a scale-in system. The computation in these systems is de-centralized within different cores. Most of the scale-in systems are multi-threaded systems with the ability to run on top of several processors. Eg. Of scale in system is multiple instances of databaseserver running on multi-core server.


Scale Out systems:



Scale out system is also known as horizontally scalable systems. Both scale up and scale in systems face several discrepancies when the overall dataset that the system handles is quite large. Processing such a massive scale dataset could really be a daunting task for those systems. Scaling up means going out from few core single machine to several commodity machines. Each node contributes to scaling out for these systems. Addition of additional nodes increases the overall scalability of the system. These systems could be single or multi threaded and the computation is de-centralized. Massive level of parallelism could be leveraged for distributed processing of huge datasets. Google Map Reduce has been the technology buzz as far as scale-out systems are concerned. Products like Hadoop, GreenPlum, Vertica and TeraData are scale out systems with all of them having support for Map-Reduce style of distributed job processing. Hadoop for example could scale out to several thousand commodity machines. The most noticeable things about these architectures is that all of them are shared nothing architectures. In shared nothing architecture every node is independent to any other node in the cluster and can perform its tasks independently. These systems could be single or multi threaded and the computation is always de-centralized.

Sunday, September 25, 2011

Hike to SarangKot and RSR 2011 August 12

This was my first hike coordination and I was feeling a sense of responsibility as well as excitement towards the plan. This hike meant more to me than just go to some place and have fun. I was to make my first maiden hike to sarangkot, Pokhara which was something I had kept in my minds for quite a long time and besides this being my first trip there, it was meant to make me fly. We were about 10 people going and the top at the plan was to glide in a parachute. All fingers were crossed but we were still at the mercy of the weather of pokhara. Gliding in the sky was by far the most exciting aspect of our hike. To view the wonderful valley from the sky was something we would really dream of. But it was going to happen this time.

The trip started late as expected. The culprit were babinz and Pratik: the last hikers to arrive at D2 premises. We passed our time playing ping-pong and carem. Finally, they arrived. Thanks to them for making our trip, really I appreciate them coming. Better late than never. So, here we are at the premises of our workplace. This is when we managed to take our first snap. Missed other guys. May be Rajani, she took this picture. But nevermind we had officially started our travel with a sense of excitement and expectations of what was about to come.


First snap at D2 Premises





Here we are at Kalimati, Now wait on for a second. We were meant to go to Sarangkot. So why are we at Kalimati ? Does not makes sense. Does it ? ya, we stopped at kalimati, kathmandu at a restaurent to have our breakfast. Nothing special. Sandwiches, omlete and Tea was what we ate as far as I remember. Because our budget allocated by our office for the hike was limited, we had to make sure that we paid our personal expenses if there were an additional cost above our estimation.



BreakFast at kalimati






Its quiz Time. Babins looks happy. Now dont blame me. My grammar is correct its his name which is plural :)


Memory card full of songs was there but something different was needed to make the trip even more eventful. So, I had decided the earlier night that I would make some questions and let the guys play a quiz while we were in the VAN. Bikesh dai was selected as the quiz master and things went rather well. All of the hikers got their share of shots on giving a correct answer.






Lunch @ River side Resort (me, ashish and Shamesh dai) shamesh dai looks happy


Our plan made a twist when we suddenly decided to take a lunch at River side resort in Kurintar. I had not been to RSR before so was at mercy of other guys who had gone there earlier to decide whether to have a lunch there or somewhere else.





Babins wants more than just a lunch. may be swimming :)



For those people who haven't been to RSR : guess what is this ?





Swimming pool water was awesomely cool

Now this was one of the best part of our travel. Swimming at RSR. The water was extremely cool. Even the guys like me and Ashish who could not swim decided to jump into the pool to join the fun. It was worth of an experience. Some guys even jumped in the jumper including me at the same location. That was fun too.






Devis Fall - Dipesh with his SLR and Bikesh dai smiling as always



Here we are at Pokhara. We arrived at saturday's evening and booked a lodge for us and went to WoodRock for some live music. It was fun. Gunjan was the pick of dancers at woodrock. He had a lot of fun including other guys. The other morning after the hangover, We decided to pay a visit to Devis fall. The waterfall although looked small in width had extremely strong current. We had our breakfast at devis fall and Lunch at local Thakali. We went to phewa lake for 1 hour boating. It was fun. But above all, We were waiting for the magical time to arrive. The paragliding was scheduled at 11 o'clock. But, unfortunately it was shifted to 2 o'clock. God knows why ? we were waiting at the agents office when suddenly at 1:45 black clouds appeared out of nowhere. Our plan was completely ruined by the weather. With heavy heart and drooped face we decided to return back to Kathmandu but with a spirit that we would come back again.











Time to be sailors at phewa lake











Begnas Lake





True Hikers. Tired, exhausted but onto their destination





All guys happy





Me happy at the pool







Rajani taking a snap







Night at Pokhara Pipal Bot







Night Time party at WoodRock






After two days of excitement, drama, fun. we returned back to kathmandu on sunday evening prabably at 8 o clock. On the way back, we took some snacks : fried fish and shrimp at Mugling. Well Ram dai gave all of us nightmares when he drove from pokhara to kathmandu. Certainly he is a cooler driver than that. Now this trip was a real good one if I forget the last time cancellation of our paragliding plan.