Sunday, June 22, 2008

Performance Tuning

Now a days many projects failed due to performance constraints and server load problems.

These tips and tricks will help many of us to solve performance related issues.

Programming Approach:

1. Avoid using static variables.
2. Avoid using Loops if possible.
3. User Additional variables to check states and validations for example:

In banking application, we want to fetch list of eligible candidates for loan then we break things into some parts
1. Fetching list of candidates for that loan.
2. Iterating them and finding their record for another loan application, checking in defaulter list.
3. Now for particular employee document verification check will be done.
4. If everything suffice then business rules will be applies to that list.

Here some general validations are
1. Employee's eligibility check
2. Checking in defaulter database.
3. Checking for document submission Yes/No.
4. Business Rules calculations.
By simply writing complex queries(applying joins) we can reduce all above 4 checks into flags like
isEligible, isDefaulter, isDocumentAvailable etc. when fetching results from query this can be used to operate accordingly.
In heavy list it is further useful to take advantage of mathematical calculations at query level. It helps in saving iteration and various flag values.
We can also check for multiple validations at one time by providing different validator objects including flags and relative checks.

4. Query Level Calculations: If records list is quite high, its better to calculate at query level rather then reiterating records to calculate values.

5. Using Language specific suggestion and tips and tricks:
Like we can use StringBuffer instead of String in java for strings subject to change. In some languages,using regular expression is quite heavy. avoiding equalsWithIgnoreCase to equals.
Minimize casting operations by taking variables according to their behavior i.e. float, int etc instead of String.

6. Properly utilizing tools like synchronization, serialization, bit arithmetic and replacing small conditions with conditional operations in place of switch case or condition statements hierarchy.

7. Using HashMaps for constant variables instead of declaring it as plain objects.

8. Separating error/exception handling throws from business rules, Its better to properly handing known exceptions to take actions rather then doing pre check.
e.g. In above mentioned banking example, We can make some checks for specific conditions that whether any employee false in that range or not. Whether employee information is valid or not. This exceptions can be thrown by your query and can be caught at exception handler unit. So its always better to reduce database load by properly utilizing exceptions.

9. Using Interfaces instead of Classes and using light weighted data types provided by language.

10. Minimize query load for properly utilizing connection pooling mechanism: Most critical reason of failing to performance constraint defined is query load, because it may affect with quantity of data. We can minimize queries load by writing complex queries, using function and procedures and performing query optimization and caching at different levels.

11. Light weighting exception related components: Sometimes its quite beneficial to use custom exceptions to work with different type of business rules, we can further optimize it and treat accordingly. Its good to use external mapping files(may be text,hashmap) for error messages and related information.

12. Programmer should not compromise at coding standards specially indenting, variable declaration and using simple functions instead of nested functions. Apart from it, it is always better to take dummy/temporary variables instead of recalling big objects again and again.

13. Optimizing member variable calculations: For any object, it is recommended that state variables should be modified according to data operations defined on that object.
For example: In maintaining account records in banking example mentioned above, that class should automatically vary different states like(total accounts, last indexes, account types etc) with incremental approach rather than calculating all things at one functional call.
Increment approach can be efficiently used at many other places also(like interface,DB to DB transfer etc).

14: Minimize load at synchronized junctions: It is better to do alternative checks(constraints, validations etc) before making any object entrance at synchronize state. It will help in filtering objects and reducing load at synchronized channel. Synchronized code should be optimal and efficient.

Remaining Tips will be updated soon..

Sunday, December 24, 2006

WINDOWS STARTUP:PROBLEM AND SOLUTIONS

1. Uninstalling any application when OS is corrupted: many times the OS get corrupted due to external causes. So we need to unistall some conflicting applications. In safe mode, generally uninstallation of the component is not possible. For this you can try the following
After booting in safe mode.
Go to Start->Run>Msconfig
Now remove many unimportant services for the timing but check Windows Installer service, then reboot the system. Boot it in normal condition. Then you can continue the process of uninstalling the application.
2. REGISTRY PROBLEM?? Have u suffered the problem.. Registry not found or Error in registry in that type of problems. the best thing is to replace current with backup copy. Like LAST KNOWN GOOD CONDITION at startup menu of windows or if you have system restore then restoring to the older point will help you a lot. The registry problem can occur if you have'nt installed the software properly. For this Unistall the related software using step 2 :)
If the problem not solved. Then REINSTALLATION CAN ONLY HELP IN MANY CASES.
3. SYSTEM FILE MISSING or related: It can be solved by many ways.
1. Start->Run->SFC then check for alter file scan or just write the file name and give them the setup path.
2. Search for file, if found send it to desired folder(WINDOWS,SYSTEM or SYSTEm32 in general)
3. Above not working, Restart the system in command prompt only mode. Go to the setup directory. and write
"extract/a" then starting cabinate file name e.g. DRIVER11.cab then desired file name. The file got extracted, then send it to the desired folder