Friday, June 17, 2016

Basic steps while dealing with application slowness due to database

In this blog I will share my experience of improving web application performance. Application slowness is often faced in large scale applications. Slowness can happen due to multiple factors and one of the major factor is because of bad database design.

Recently I got a chance to work on an application optimization task. The whole activity includes many areas that are focused and optimized. The main performance improvements are though after database optimizations are done. I am listing down some of the major activities that are performed and found very helpful in finding performance improvement areas.

Is it really a database problem?

Get web server traces and find if there is performance issue in the application itself. Before saying that DB is the only issue just double check by getting and comparing the web server traces and SQL-Profiler traces. Confirm that most of the time taken by request is through database and not something from application itself.

Execute and check SQL-Profilers

Execute the SQL-Profiler and check the queries/stored-procedures that are taking most of time. Notice both duration and read counts in causing application slowness.

Check proper indexes

From the profiler traces one can easily identify the queries or stored-procedures that are taking time. Once those are identified, first thing you have to look is to check your indexes on tables used in queries or stored-procedures. Add appropriate indexes on required columns.

Execute query execution plans

Before I was not very friendly with this feature of Microsoft SQL Server. The Actual Execution Plan of a particular query or SP is very helpful in finding out the specific area that is taking time. The execution plan also suggests the indexes that can fasten up the execution. The suggested indexes can be applied on tables and the impact can be re-checked by executing query/SP again.

Use JOIN instead of IN statements on large data

Other than indexes do go through the statements either those can be overwritten more efficiently. For example instead of using IN clause use JOINS if the data is too much for IN clause.

Check for LOCKS

Specifically taking about MSSQL, it has different pre-defined SP calls that can hep in identifying locking information. For example sp_who2 and sp_lock SPs can be called to get locking information. Statements can be locked due to synchronous Update/Read hits are made on a same table in database. One of the statements can be blocked/locked until other statement releases the table lock.

Use WITH (NOLOCK) where ever required

Do not use WITH(NOLOCK) everywhere. Use it where ever required. I am not going to mention the details of using/not-using WITH(NOLOCK) but I will suggest to read some helpful articles related to this.

Check database statistics

Database statistics can be find out from sys.stats system table. sp_updatestats command can be used to update database statistics. Index rebuilding can also happen statistics update. These activities are not mandatory but if for some reason your database indexes goes bad you have to update/rebuild them. Bad database indexes cannot only return false results but can also make the query/SPs very slow to execute.


Thursday, December 31, 2015

Karachi, the upgraded one !

I last visited Karachi just a year ago and I feel dramatic positive change in Karachi in my current visit. Following are my observations:

  • The scary mode in Karachi public is gone. They looks more energetic and motivated.
  • Business is back and people are keen to invest in different sectors.
  • Too many food places. People are investing in food centers most commons are Pizza outlets, BBQ's and Fast foods.
  • Technology acceptance in small business which includes general stores, food chains, clinics etc.
  • Chingchis are gone. Makes traffic a bit better
Hope things will become much better in coming time and the true potential of Karachi will rise.


Friday, September 26, 2014

Android Library Project and its usage

"Android Library projects contain shareable Android source code and resources that you can reference in Android projects. This is useful when you have common code that you want to reuse. Library projects cannot be installed onto a device, however, they are pulled into the .apk file at build time." 

When creating a new Android project you can mark a project as ‘Library’ project. This will create a project that can be shared/used in multiple projects. You cannot run/install the library project stand alone instead you have to reuse it in Android project.

How to mark a project as library:

Create a new Android project that will use the library project. Library project can be added as reference as follows:
  • Android Project > Properties > Android (left option) > Library (bottom right pane) > Add


Click ‘Apply’ > ‘OK’

  • To use the library class activities in android project, 'import' the library references where ever you are using library files.
  • To launch the library activity you should have that activity listed in your Android project 'AndroidManifest.xml'.
  • Don’t make files (Layouts, Classes, XML’s) with the same name in main and library projects. This can cause problems at run time. What I have noticed is that if you have same name layouts in both projects the library layout got overridden and parent layout will be used.


Saturday, September 13, 2014

Bahrain - Buildings and Architecture

Bahrain is one of the very fast growing countries around the Arab world and is considered as a major tourist centers in Middle East. Some major development has been made in last few years to make country more tourist attractive. Though Bahrain is a very small country but it still has a potential to generate a good revenue and maintains good standard of living. Lets look at some of the renowned places in Bahrain where I have been so far:

Bab Al Bahrain (Gate of Bahrain) is a historical gate of Bahrain which now a days is used as an entrance to Manama market. Previously it was with the edge of sea and fishermen's are used it to starting point of fishing and trading.

This is Bahrain's Financial Harbor building, the tallest and modern building on the main Bahrain highway.

Mosques in Bahrain are very attractive and some of them are kept as historic. Al Fateh Grand Mosque is the biggest on island.

This is Bahrain World Trade Center the most renowned structure in Bahrain. It is close to main (King Faisal) highway. This unique structure is a tower complex connected with three bridges having wind tribunes on it. These tribunes helps in power generation that is consumed in building. Making of this structure is also covered in National Geographic as one of the mega structures.

Bahrain Circuit (Area for World Formula One Championship): The Bahrain International Circuit is a motorsport venue opened in 2004 and used for drag racing, GP2 and the annual Bahrain Grand Prix. The 2004 Grand Prix was the first held in the Middle East.

Skyline (Manama and Al Muharraq):

Bahrain Museum and other visiting points:

Amwaj Lagoon:

Random Structures:

Lots of Malls are in Bahrain such as City Center, Seef Mall, Geant, Dana Mall, Bahrain Mall etc.

Some good parks, water parks are there for family outings.

More will be added as soon as I will be visiting there.


Friday, May 30, 2014

Manipulating PDF document using iText library

There are several libraries that can be used to manipulate a PDF document like PDFBox, iText, PDFClows etc. I also have to do some PDF manipulation stuff and I decided to go with iText. I choose iText because it supports low level PDF manipulation, its community is very strong, lots of helping hands are available and it is also open source and available in both Java and C#.

iText allows you to create a PDF doument, add content in it, update content and save it. I have tried following basic features so far and found it really interesting:

  • With low level support one can add a text chunk, paragraph, phrase, link, chapter, section, image, set text color and other attributes into the document. 
  • You can also create a table/grid inside a PDF document and play with each cell of the table.
  • It is also easy to read an existing PDF document. You can retrieve existing information related to document and pages.
  • Using iText one can also fill up an empty PDF template.
  • It allows to set javascript in a PDF document to make a document interactive. Document can be also be navigated to a particular page. Creating bookmarks, annotations and triggering javascirpt from a button can also be done using iText.
  • Document can also be password encrypted to allow/disallow certain actions that can be done the document.
  • Whole PDF document can also be signed using a certificate to make the document secure.
There is also a book on how to play with PDFs using iText in ActionHe is the author of iText in Action and is very supportive on stackoverflow. I also have some questions regarding iText on stackoverflow on this link.


Friday, September 20, 2013

A Step Forward - Working abroad now !

After working for more than six years in different software companies of Pakistan, now its time to move forward and accept the opportunity to work abroad. This is my first experience to work overseas and live without family. I hope I will settle in the new environment soon.

I moved to Bahrain in mid August 2013 and joined a software company 01 Systems WLL (ZOS).

"Since its establishment in 1986, 01 Systems has become a pioneer in implementing complex, customized software solutions coupled with comprehensive professional services like Consultancy and Systems Integration to successfully optimize core business processes."
The company is established in the same year when I was born. With over 25 years of services in software industry the company is well established and has solid software products in market. It is a good chance for me to work on these large scale products and add my experience to them as well.

I hope everything will go smoothly and this will become a worthy experience in my career.


Saturday, August 31, 2013

Quran with Urdu Ta-laf-fuz and Urdu Translation

Quran Asan Tehreek has come up with some great ideas to make the Quran-e-Hakim reading/understanding easily and correctly. I got very impressed with one of there ideas of Urdu Tal-laf-fuz of Quran-e-Hakim. This will make it quite easy for those who can read Urdu but not Arabic.

Quran Asan Tehrik has, compiled  translation of Quran-e-Hakim in two colors, the Arabic word written in a colour bears it’s meaning in the same colour, the text and the translation go side-by-side together on a page, making it extremely easy to ascertain which Arabic word means what. This method provides  the reader an easy understanding of the Arabic as a language and also builds up potential of the reader to comprehend Quran-e-Hakim directly without the aid of any exterior help.

Look at the sample page: