In addition to the common optimization tips for SQL Server query, the following are some of the useful tips.
- To view the row count from a table use, "SELECT rows FROM sysindexes WHERE id = OBJECT_ID('table_name') AND indid < 2" query instead of count(*) or use sp_spaceused which will also provide the row count.
- Avoid having clause in group by and use where if necessary
- Avoid distinct clause and use it only when it is really mandatory
- Include SET NOCOUNT ON for stored procedures as it will reduce the transfer of rowcount data travelling from database to application
- In case you need to get only first n rows in a query use top or SET ROWCOUNT statement.
- Avoid using optimizer hints in any database. This may make the query faster initially but will really affect the performance as the data grows in the table.
- Try to use inner tables instead of creating temporary table whereever possible.
- Use a EXIST, NOT EXISTS or LEFT OUTER JOIN instead of a IN or NOT IN in where clause.
Wednesday, April 23, 2008
SQL Query Optimisation - Other than common ones
Tuesday, April 22, 2008
Common code smells
Type codes and switch statements are common code smells. In addition, there are quite some other code smells that are also very common. Below is a summary list:
- Duplicate code.
- Too many comments.
- Type code.
- Switch or a long if-then-else-if.
- Cannot give a good name to a variable, method or class.
- Use names like XXXUtil, XXXManager, XXXController and etc.
- Use the words "And", "Or" and etc. in the name of a variable, method or class.
- Some instance variables are not always used.
- A method contains too much code.
- A class contains too much code.
- A method takes too many parameters.
- Two classes are using each other.
- Duplicate code.
- Too many comments.
- Type code.
- Switch or a long if-then-else-if.
- Cannot give a good name to a variable, method or class.
- Use names like XXXUtil, XXXManager, XXXController and etc.
- Use the words "And", "Or" and etc. in the name of a variable, method or class.
- Some instance variables are not always used.
- A method contains too much code.
- A class contains too much code.
- A method takes too many parameters.
- Two classes are using each other.
Monday, March 31, 2008
IIS Performance issue
The normal issue that comes up with the web applications hosted on IIS is related to performance. Coincidentally I came across these issues recently in my area of work. I hope this information will help to those who face similar issues.
Here are the basic steps to do when faced with performance issues in web applications:
- Check if the process Aspnet_wp.exe (IIS 5.0) or W3wp process (IIS 6.0) is consuming high memory in the server.
- If the memory level is higher, then it may affect any other services or applications running on that server.
- In case, the requirement of the application requires more memory then upgrade your system to have higher memory to support the application
- Check the Web.Config file if the Debug, Trace or both are enabled. To accomplish this, ensure that the web application is deployed to production always in release mode.
compilation debug="false"
trace enabled="false"
- Check if the executionTimeOut attribute is set to higher level. This should not be set to higher level in production environment. This will hold on to the thread till it timeout and increase the level of memory usage.
- The performance can also be improved at the coding level by avoiding any string concatenation process and instead use the StringBuilder for the purpose.
- On the software installation, ensure that .NET framework 1.1 SP1 is installed.
Here are some additional tips for writing High – Performance Web applications
http://msdn2.microsoft.com/en-us/magazine/cc163854.aspx
Here are the basic steps to do when faced with performance issues in web applications:
- Check if the process Aspnet_wp.exe (IIS 5.0) or W3wp process (IIS 6.0) is consuming high memory in the server.
- If the memory level is higher, then it may affect any other services or applications running on that server.
- In case, the requirement of the application requires more memory then upgrade your system to have higher memory to support the application
- Check the Web.Config file if the Debug, Trace or both are enabled. To accomplish this, ensure that the web application is deployed to production always in release mode.
compilation debug="false"
trace enabled="false"
- Check if the executionTimeOut attribute is set to higher level. This should not be set to higher level in production environment. This will hold on to the thread till it timeout and increase the level of memory usage.
- The performance can also be improved at the coding level by avoiding any string concatenation process and instead use the StringBuilder for the purpose.
- On the software installation, ensure that .NET framework 1.1 SP1 is installed.
Here are some additional tips for writing High – Performance Web applications
http://msdn2.microsoft.com/en-us/magazine/cc163854.aspx
Saturday, March 29, 2008
Making the beginning is one third of the work done.
This is my first blog. I have started this for a purpose. As the thought goes in the quote:
"No story is the same to us after a lapse of time; or rather we who read it are no longer the same interpreters." - -- George Eliot
So does my thoughts behind this blog. We learn many things in the course of our daily work, especially in working with technology we learn a particular concept only when it is faced as an issue by us. There is no common solution provided for a particular issue. The approach differs by person, time and environment. In such an environment, knowledge sharing is now the popular concept across the IT sector.
I hope my blog will add value to the knowledge sharing chain
"No story is the same to us after a lapse of time; or rather we who read it are no longer the same interpreters." - -- George Eliot
So does my thoughts behind this blog. We learn many things in the course of our daily work, especially in working with technology we learn a particular concept only when it is faced as an issue by us. There is no common solution provided for a particular issue. The approach differs by person, time and environment. In such an environment, knowledge sharing is now the popular concept across the IT sector.
I hope my blog will add value to the knowledge sharing chain
Subscribe to:
Comments (Atom)