Wednesday, July 15, 2009

Before You Say "It's Not Working"

A few days back a couple of interns working in my office came up to me and said "It's not working". They were talking about a part of an application they had built. Their application was invoking an API given out by my team and it was throwing an error. They were invoking one of our Web Services through a client side Java API provided by us. Their app was running on Tomcat and that was accessing our product that runs on another Tomcat server. So they have access to both these servers. After we exchanged a few IM messages we solved the issue - but I am sure that if they once again face any issue, they would not immediately ping and ask "Why is it not working?".

After we figured out the issue, I was thinking of sending a note to the interns on the first step they need to do when they face any such issue and I ended up writing this.

Check the Logs. Repeat- Check the Logs.

From what I have seen 99.99% issues get solved the moment you Check the Logs. And Yes, many people don't do that before they report the issue. In the present case, the WS client in the SDK was throwing an exception and it said "An Error occurred with the client". So when they were seeing this, they actually could not make out anything. But that was at the client side. The first thing anyone should do is check the server logs. Server logs in this case would mean the Application logs on the App Server where the service is hosted and the Application server's own logs.

Many times you see that the logs are way too much to deduce anything. They run into pages. And I have seen, this very fact demotivates any newbie who looks at it. In that case, If the issue can be replicated I suggest -

  • Shutdown the server and client
  • Backup your logs
  • Cleanup the logs directory
  • Restart the servers and reproduce the issue


Now the logs are much lesser and comfortable to read. Also it would be helpful if you can clearly separate the server start-up logs from the subsequent logging that happened during the issue replication. Now read that line by line and most of the times the issue would be solved. If not, read every line of the logs few more times. Yes, Few more times.

Still unable to figure out?

Check the logging level

Every logging framework provides you various logging levels, that you can configure. Most of them have a "debug" logging mode, which when enabled- logs the most granular details. Enable this level of logging on the application and the server. Well written applications log their code flow on to the debug level. Hence with this level of logging set, there is a very high chance that you get to reach the root of the problem.
Even if you are not able to figure out the issue even after looking at the debug level logs, you still have helped the person who has to take a look at them. You have reduced the turnaround time. These debug logs will definitely help the API/Service developer who is going to look at your issue. He now has most of the information with him.

Not everything on the Server - There's client too

Most Apps are like this - You write a client program that accesses a service running on a server. The Application that runs on the server would also provide client side API's that would do the task of marshalling your arguments and passing it on the wire through SOAP/RMI etc. A whole lot of things happen between the time you invoke the client API and the time the message is sent on the wire (Goes out of this VM). The same is the case when you get the return message - from the time the message comes through the wire and till the time it's handed over to your client program, in the format it accepts. Typically these are marshalling/unmarshalling tasks carried out by the client side API's. Now the concern is - what happens if something goes wrong here?

Most times we ignore the logging/trace on the client side. Yes, on the client side too you could configure the logging level. The way you do this depends on the logging framework that the API you are accessing uses. Most times you would have to place a logging config properties file in the client classpath. The logging framework on the client API that you use, loads this file and determines the level of logging and the appender/handler to which logs have to be written.
So once you have the client side logs, you would be able to figure out what really was sent from the client, what it received and other info related to marshalling/unmarshalling etc. One suggestion that I have here - In case you have access to both the client and server ensure that both of them have the same system time. With this, you could easily track the flow from client to server and the way back with respect to time.

All these really help even if you are debugging an issue on something that you have developed or are developing - Something that can be done before debugging your code by placing breakpoints or even worse - by adding those System.out statements.

Too many threads?

Imagine the case where you have too many threads in your application that are doing their work simultaneously. The log records might be jumbled together. In such a scenario, to be able to uniquely identify and track the flow of one particular thread, you could have an identifier in the log record that contains the thread name.

Logging only failures?

A lot of times when your application is running on production, it would not be a very good idea to log all of the threads on the server side. You would be interested in logging only the failures. In such a case, what you typically do is - Accumulate the log records for each thread and at a later point of time depending on the success or failure of that thread, you decide whether to write its records to the log files or not. Note that these records are in the memory for the whole duration of the operation - and that could be quite expensive.

Beware

Most application servers would have their own logging framework which logs the tasks performed by the server. In certain logging frameworks you need to tell the framework when to start and stop logging on a thread. So when the server assigns a particular thread from a pool to your request it would do the job of telling the framework to start the logging. So If you explicitly create threads on an application server, these threads might not be logging information at all, though your code might have log statements.

Another important thing to note is not all issues that you encounter will get replicated even one more time. A lot of times I have seen that the moment you change the logging level or add a new log statement the issue goes away. Often this the case with issues related to multi-threaded programs, where even one new instruction would change the code dynamics or timing.

Solved. What should I do?

If a log information really helped you to better understand an issue, you then have a very important learning. You too should "Log" in your application. Many times I end up spending more time determining what should be logged and at what levels than the time I take to write the code. After all, logging is an art.

Update: Also appeared at http://java.dzone.com/articles/its-not-working-first-steps

11 comments:

website design,web design said...

Your blog is very nice... i like your blog ....

Anonymous said...

Hi !.
You may , probably very interested to know how one can make real money .
There is no initial capital needed You may start to receive yields with as small sum of money as 20-100 dollars.

AimTrust is what you haven`t ever dreamt of such a chance to become rich
AimTrust represents an offshore structure with advanced asset management technologies in production and delivery of pipes for oil and gas.

Its head office is in Panama with affiliates around the world.
Do you want to become really rich in short time?
That`s your choice That`s what you wish in the long run!

I feel good, I began to take up income with the help of this company,
and I invite you to do the same. If it gets down to select a proper partner utilizes your savings in a right way - that`s it!.
I make 2G daily, and my first investment was 500 dollars only!
It`s easy to start , just click this link http://odasukixab.freecities.com/uwisot.html
and lucky you`re! Let`s take our chance together to become rich

Anonymous said...

Dear Author thoughts.bharathganesh.com !
What is it to you to a head has come?

Anonymous said...

I want to quote your post in my blog. It can?
And you et an account on Twitter?

Anonymous said...

I want to quote your post in my blog. It can?
And you et an account on Twitter?

Anonymous said...

I want to quote your post in my blog. It can?
And you et an account on Twitter?

Anonymous said...

topic14, [url=http://www.chop.edu/forum/user/profile/8207.page]klonopin no prescription[/url], :-) fsb, http://www.chop.edu/forum/user/profile/8207.page buy klonopin :-), [url=http://www.chop.edu/forum/user/profile/8208.page]cheap xanax 2mg[/url], :-) gqi, http://www.chop.edu/forum/user/profile/8208.page buy xanax 2mg :-(, [url=http://forum.cprs.ca/default.aspx?g=posts&m=6]order adipex online[/url], ;-( pqj, http://forum.cprs.ca/default.aspx?g=posts&m=6 order adipex online ;-(, [url=http://forum.cprs.ca/default.aspx?g=posts&m=7]buy alprazolam no prescription[/url], :-) xui, http://forum.cprs.ca/default.aspx?g=posts&m=7 buy alprazolam no prescription :-), [url=http://forum.cprs.ca/default.aspx?g=posts&m=8]buy ambien no prescription[/url], ;-( cxc, http://forum.cprs.ca/default.aspx?g=posts&m=8 ambien no prescription :-)

Anonymous said...

Good day, sun shines!
There have were times of hardship when I felt unhappy missing knowledge about opportunities of getting high yields on investments. I was a dump and downright stupid person.
I have never imagined that there weren't any need in big initial investment.
Now, I'm happy and lucky , I begin take up real income.
It gets down to choose a proper partner who utilizes your funds in a right way - that is incorporate it in real business, parts and divides the income with me.

You may ask, if there are such firms? I'm obliged to tell the truth, YES, there are. Please be informed of one of them:
http://theblogmoney.com

Anonymous said...

hi! [url=http://esnips.com/web/minnaregina/]Hello. And Bye.
[/url] http://esnips.com/web/minnaregina/ free nude video clips of milfs
thanks!
free nude video clips of milfs

Joshua Smith said...

Thank you for sharing with useful subject. It is required to understand that company providing it outsourcing services, could help in your business by installing custom software applications.

gregnazvanov said...

love your post. However, after working with interns I'm going to say....it's not working