Those of you who are involved in real time application development surely have suffered from the unexpected GC pause time. I have spent quite a bit of time trying to tune my Heap generation spaces, playing with new generation / old generation size , GC algorithms etc. I had my eye on the Sun’s Garbage First Collector. Basically it is the replacement of the old CMS (Concurrent mark sweep) collectors and can be extremely useful for large heap low latency applications. I just read this article which suggests sun is going to make this commercial !!! I wonder whether the Oracle acquisition is revealing its true nature! One of the main reason why Java is still my favorite platform (I am falling in love slowly with dynamic languages like Ruby, Erlang, PHP..man! you can do magic with them !l!) is because of its solid and open VM. If sun moves away from its open policies, I wonder if Java will become the legacy language in near future????!!!.
Uncategorized
GNU Screen Essentials
Long ago, a very historic unix hacker was surprised to see I don’t know what “Screen” is! Seeing him so excited, I looked into screen. Basically it is a terminal multiplexer/emulator which gives you the facility of multiple terminal over a single terminal screen. Back then, I had just started my career and the tool didn’t seem very essential to me. If I need multiple terminal, I can just open multiple terminal, right! Huh! How naive I was. I didn’t realize the beauty of screen until I had to maintain a production system over a very slow internet connection where I had to first ssh into one machine, from there, ssh into another machine, then do the work. I had to do this for 3-4 terminal just to get going, But that isΒ until I started to use Screen properly. Now I open a single connection and use Screen to emulate multiple terminal. The added advantage is, You don’t loose your ssh session even when your connection goes down, you simply reattach to that session after reconnecting. This is specially helpful when you don’t want to stop your process even if the terminal that spawned the process dies. (You can also use nohup for that).
First install screen:
$ yum install screen
Anyway, here are the screen commands that I use frequently and can help you get started.
1. Start Screen:
$ screen
You will see some greeting message. You can set it off by putting this line in your $HOME/.screenrc file
startup_message off
OK, now you can see the same old terminal screen where you can do anything that you used to do in your main terminal. But keep in mind that, its not your regular terminal, you are actually in the “Screen” application. So this is your base screen terminal with index 0. You can continue your work with it.
Now, If you want another terminal, on the “Screen” terminal, hit
CTRL-a CTRL-c
. You are now in another terminal(this with index 1). To go back to previous terminal, hit
CTRL-a '
(that is press CTRL-a and then press ‘). you will see an emacs style prompt asking your the index: .
CTRL-a CTRL-a
will switch between most resent two terminal.
CTRL-a 1
will directly take you to terminal 1 .Β Cool! Now you can start as many screen as you want and play around! If you want to list all active screen terminals :
CTRL-a "
Now that you have the very basics of screen, here comes the most powerful feature: Attaching to a previous screen session and Detaching from an existing screen session.
When you are inside screen, press :
CTRL-a d
This will detach you from an existing screen session. To connect back to the screen session use:
$ screen -r
It will connect you to the screen session, But what if you have multiple screen? You can see the screen list like this:
$ screen -ls
Now you can use the screen name to reattach:
$ screen -r mysession
But you surely don’t like the screen name which is provided by default. You can provide a screen session name when you created a screen session like this:
$ screen -S mysession
Now that you get the basics and have the feel for it, you can explore more advanced options like cut/copy/paste , history etc.
I’ll leave that on you to explore.
Evidence Based Scheduling, Estimation and Scrum
People who know me would be surprised to see me talk about Estimation, Scheduling and all the related stuff. To be frank I consider that quite boring and better be left alone for managers! However, I am so loving the new process called Scrum we are following for last 6 months, I thought I should write a line or two about it.
Long ago I was reading this article by Joel which talked about doing your scheduling/estimation based on the evidence. What evidence you may ask? If I understood it right, the evidence is your team’s efficiency! Being used to have the people who has no Idea about what the “NEW FEATURE” is and doing the estimation, I kind of liked the idea. How many times have you stayed late in the office to finish the “Cool and Easy” feature that your manager Promised to deliver the next release? I always felt the manager, no matter how experienced or skilled he is, should not be solely responsible for the estimation. We are in the business of programming, and programming is art! Its not the construction business, its not the military. For any work of creativity, you need freedom and comfort. Until we adopted scrum, I was always wondering how the developers can be a part of the whole management thing specially given the lack of interest of the developers in such things.
I am not going to describe what scrum is and what are the common benefits of following scrum, you will find plenty of reference in the net. I’ll just point out what are the things that I think scrum is so effective from estimation point of view and lucrative from a developer’s perspective, So here is my two cents:
1. The Team does the estimation! Your team is composed of people with diverse skill sets. When you throw a new story to a team, at least 2 of the team members would have some kind of idea about how to do it. For some other story, may be some other team members will put their input. So the estimation will be as good as it gets. And after two or three sprints with the similar kind of stories, the estimation should be perfect!
2. The Developers make the Promises! If you are some investor in any software business, and want to have some feature done within a specific time frame, here is a piece of advice from a man in the tranches, ask your developers, not the manager! If a developer commit he will get something done within a specific deadline, he will. We developers are so dumbly proud that we will even sacrifice our personal life to meet the deadline that we promised. On the other hand, if you ask your manager, he will just keep pushing the developers because he can’t do the things himself even he wanted to. That way, you will end up with a buggy and messy product which is the outcome of all the hatred and frustration that your developers produced during the overtime that they did. Scrum does not have a project manager! Scrum has a Scrum master whose responsibility does not include estimation! It is the team who did the promise during your sprint planning that they will accomplish the features. Any self respecting and efficient team will thrive to achieve that. You will be surprised to see the team requesting you to keep the workspace open during the weekend so they can polish the stories for the reviews! Self-management– this is what scrum is all about. In a manager led project, not all the team members share the same responsibility as the manager. Since the manager is solely responsible for all the planning and estimation, other team member doesn’t event feel responsible for the project because they are not at the gun point! This is specially true when the manager tries to accomplish some impossible deadline.
3. The Estimation is based on Evidence! Right after 2 months of following scrum, we kind of knew our team capacity is 80 points per 15 day sprint. After doing 10 sprints, we can now almost 90% accurately tell that if we plan 100 points, we are going to do overtime and we plan 60 points, we will be relaxing! How do we calculate the 80 point? The stories or the tasks that we estimate are constantly compared with the stories or tasks that we did in the previous sprints. We will say, it took us 2 days to do that “user registration form” with all the unit tests and automated tests which was a 5 point story. So we think the “user account detail collection” is a 8 point story which will take 3 days. Simple yet so efficient! One thing about estimation we don’t give much importance is our hunch or intuition! But we develop our ability to “guess” over so many trials and errors! Our subconscious mind is constantly collecting and processing information and our “guess” is the outcome of that. When 6-7 people are guessing something, its the fruit of years of experience that should not be overlooked. It is as close an estimation as you could ever get.
4. Scrum is sustainable! Scrum is by the developers , for the developers :). Forgive my cheap joke, but couldn’t help it ! We are making the estimation, we are making the promises, we decide whats best for the product, we choose the technology, we take the pride! We don’t have a manager to micromanage us, instead we have a scrum master to lead us. We work for ourselves, we work for the team, we work for the product. The satisfaction that this brings us can’t be compared to anything else, no amount of money or facilities can bring this. We don’t feel sick every week, we don’t think we are underpaid, we don’t feel the constant anger, we don’t think about skipping the office each morning, in a word, we don’t burn out! We are happy developers who have fun in the workplace. Believe me, if you want a good product, you don’t need fancy office or fancy furniture or worlds best salary package or even worlds best programmers. You need happy and motivated developers who are smart enough to get the job done. I believe scrum provides the best way to get there.
Having said all these, I must warn that scrum is not for everyone. Scrum is all about self-managed team. That requires highly skilled and seasoned developers who are matured enough to self manage. Scrum requires honesty which is usually not a problem with programmers. Most of all, scrum requires teaming. If your developers can’t jell together, you will end up with highly inefficient team. One of the main reason I feel we could adopt scrum so easily is because each and every developer of the team is quite experienced and has a minimum level of competency. I wonder how we would adopt scrum if we were a bunch of amateurs.
Spring Session Scoped Bean
I have always hated direct usages of “HttpSession”. You know how tricky it becomes when you want to do advanced things like session replications / caching etc. I have previously used home grown session factory abstraction. But just recently I came across Spring “Session Scoped Bean”. So far, we have only used dependency injection of spring beans which had only 2 scopes – singleton & prototype. But now spring supports custom scopes for beans and one of them is “Session”. It means that this bean is created when a new HttpSession is created and preserved as long as the HttpSession is valid. Spring uses AOP to extract the sessionId from the httprequest and manage the lifecycle of the bean. So instead of putting your object directly into the session, you get to put them in an injected POJO based placeholder. This makes it easy to do the testing and getting rid of HttpSession dependency. So when time comes, you can use solutions like “terracotta” to distribute your session without changing your code! Isn’t that wonderful! Another niche Spring trick!
The details of how to setup the configurations can be found here. I followed the exact steps and it worked flawlessly.
“Enso”—where were you all these days!
Surfing the net is like a hobby/passion/addiction for me, And I mostly surf technology / computer related stuff! I work with other software professionals who are geeks. So anything new, useful comes to my attention early. Yet I am very disappointed to know that Its only today I came to know about Enso! I’v been using it for a few hours now but I am sure its going to be my most useful windows utility forever! It might even become a reason why I prefer Windows over Linux as my development environment [ They don’t have the linux version yet π¦ ]. Just look at the demo and try using it. Using Computer will never be the same again!!!!! I pity myself for not using it earlier π¦
The Productive Programmer
I’v been reading the book “The Productive Programmer“. Being the lazy programmer myself, I always look for more efficient ways of doing things. There are tricks I’v learned from my experience over the years and still learning new things every now and then. But it looks like this book is the summery of all that! Any developer who wants a better way of doing things must have go through this book. How many times have you come across a niche tool and said “Wow! I only wish I knew about this earlier!”. Do you remember first time you used cygwin on Windows! This book is the compilation of all those tools and tricks!
Which dynamic language to learn
Learning a dynamic language has long been on my to-do list. I have tried a little bit of everything , ruby, python even lisp. But I never could proceed much. After playing around with them for a while, I loose interest and find a new framework/tool in java or j2ee more interesting to learn and move on. Well, this time I am very serious and determined and I think it is high time to learn one as even Sun embraced the dynamic language pool into JVM.
Now comes the BIG question, which one to learn??? I know LISP should be my #1 choice according to Paul Graham. It is his book “Hackers And Painters” that convinced me to learn a dynamic language in the first place. But I just can’t bear the braces of lisp, I tried, but its too much for me to digest. Anyway, I guess its quite challenging for anyone to choose a dynamic language to learn specially when he has no idea what he is going to do with it(I don’t see myself moving away from java/j2ee in near future). After a lot of googling/reading blogs/taking suggestions, ruby & python are on the top list. But I have something else in my mind: JavaScript!
I don’t understand why JavaScript is only considered for client side scripting! I can see all the features a dynamic language can offer in JavaScript. May be I’m too naive to tell right now but I am surprised why JavaScript is not mentioned more often in the Dynamic Language Shootouts.
Its not like I haven’t used javascript before to write client side scripts but I have never looked at it as a language seriously. I only used it as a DOM manipulation tool. But the more I’m digging it, the more I am surprised to see its power. And probably, its one of the most used language ever.
So anyone got any advice for me? Any feedback to make me think otherwise? Should I switch to Python/Ruby?
How to redirect System.out.println in Java
Did you ever get frustrated with a codebase which has overuse of System.out.println??
May be it is flooding your console or even worse you need to capture the outputs to analyze them….Ever wondered how you can capture your System.out.println() ‘s of your tomcat application?? Well, you can always use IO Redirect in unix to send the output to a file. You can use find replace to change all System.out.println() to some method call which will write the logs to a file. But being the lazy programmer that I am, I always look for a shortcut. And sometimes I even find one π
I was working with this code and it had important System.out.println everywhere. I wanted to use trail/grep and stuffs like that with the console logs but I couldn’t do that on the application console. So this is what I did to redirect all System.out.println to a log file.
public class MyMainClass { public static void main(String[] args) throws FileNotFoundException {
File file = new File(\"/home/sajid/sysout.log\");
PrintStream printStream = new PrintStream(new FileOutputStream(file));
System.out.println(\"1\");
System.setOut(printStream);
System.out.println(\"2\");
}}
Did you ever notice that System.out is just another PrintStream and you can replace it with your own? This is why I love java. You can replace many things with your own implementation. Did I tell you how I replaced the URLClassLoader with my JDBCClassLoader to load classes from Database? Lets keep that story for another post.