Thursday, October 27, 2011

Tips: Steps to customize Memory Allocation for Queries in SQL Server2008

In order to perform a query execution, SQL Server 2008 allocates a minimum of 1024 KB of memory; it is a default action. As it is a guaranteed allocation per user, you can set it anywhere from 512KB to 2GB. By increasing the minimum query size, you can improve the performance of queries that perform processor-intensive operations, such as sorting or hashing. Even if you set a higher value, you can degrade the overall performance of the system. Therefore, it is required to adjust the minimum query size only when there is any trouble in quickly executing the queries.

You can see the default setting of 1024 KB of RAM works in most cases. If the server works at an extreme busy environment, you would still have to change the value accordingly. You can do it with lots of simultaneous queries running in separate user connections, or in a relatively slow environment, with few (but large or complex) queries. There are four factors that determine your decision to adjust the minimum query size as follow.

•    The total amount of free memory (when the system is idle and SQL Server is running)
•    The average number of simultaneous queries running in separate user connections
•    The average query size
•    The query response time you hope to achieve
The fact is that you should be ready for a compromise while setting these values as you can’t always get an instant response. However, you can still optimize the performance based on the available resources. You can go with the following equation to get a starting point for an optimization.

FreeMemory / (AvgQuerySize * AvgNumSimulQueries)

For an instance, a system has 2200 MB of free memory, average query size is 2MB and the average number of simultaneous queries is 50, then the optimal value for the query size is 2200 MB / (2 * 50), or 22 MB.

You can follow the following steps to allocate memory for queries:
1.    First, it is required to open the Memory Page from the Server Properties dialog box.
2.    Then, set a value for the Minimum Memory Per Query box.
3.    This value will be set in kilobytes.
4.    Now, click OK. That’s it.
5.    If you wish, you can still use the stored procedure sp_configure to set the minimum query size. The related command is:
exec sp_configure "min memory per query",
6.    Try working on this.
B  y