Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it feasible to improve performance of SQL server with caching?

What is the most common and easy to implement solution to improve speed for SQL Server 2008R2 database & .Net 3.5 application.

We have an application with the following attributes:
- small number of simultaneous clients (~200 at MOST).
- complex math operations on SQL server side
- we are imitating something to oracle's row-level security (Thus using tvf's and storedprocs instead of directly querying tables) -The main problem is that users perform high amount of updates/inserts/deletes/calculations, and they freak out because they need to wait for pages to reload while those actions are done.

The questions I need clarification on are as follows:

  1. What is faster: returning whole dataset from sql server and performing math functions on C# side, or performing calculation functions on sql side (thus, not returning extra columns). Or is it only hardware dependant?
  2. Will caching improve performance (For example if we add redis cache). Or caching solutions only feasible for large number of clients?
  3. Is it a bad practice to pre-calculate some of the data and store somewhere in the database (so, when user will request, it will already be calculated). Or this is what caching suppose to do? If this is not a bad practice, how do you configure SQL server to do calculations when there are available resources?
  4. How caching can improve performance if it still needs to go to the database and see if any records were updated?

general suggestions and comments are also welcome.

like image 949
user194076 Avatar asked Feb 24 '12 21:02

user194076


People also ask

Does caching improve performance?

Database caching allows you to dramatically increase throughput and lower the data retrieval latency associated with backend databases, which as a result, improves the overall performance of your applications.

Does SQL Server have cache?

In SQL Server, the buffer cache is the memory that allows you to query frequently accessed data quickly.

Should you use caching in your SQL Server?

When it’s not possible to remove SQL statements that are unnecessary and the rate of change of common data is relatively low, caching SQL results can provide a significant performance boost to your application and enable additional scalability of your database server.

What is the impact of the MySQL Query Cache?

The impact of the MySQL query cache can degrade the performance for environments with heavy write to read ratios. This is due to the coarse nature of the query cache, where a change of any data to a given table will result in an invalidation of all SQL statements that are cached that use the table.

Why should you proactively tune your SQL Server?

Rather than waiting for performance problems to occur, proactively tuning SQL Server will ensure your SQL statements run as efficiently as possible by helping SQL find the fastest route in and out to deliver your query results.

What are the best practices for SQL Server performance tuning?

This article describes nine best practices for SQL Server performance tuning. The best way to ensure that SQL Server can meet its performance requirements is to implement a robust performance tuning strategy that takes into account all aspects of the SQL Server environment.


1 Answers

Let's separate the answer to two parts, performance of your query execution and caching to improve that performance. I believe you should start with addressing the load on your SQL server and try to optimize process running on it to the maximum, this should resolve most of the need to implement any caching.

From your question it appears that you have a system that is used for both transactional processing and also for aggregations/calculations, this will often result in conflicts when these two tasks lock each other resources. A long query performing math operations may lock/hold an object required by the UI. Optimizing these systems to work side-by-side and improving the query efficiency is the key for having increased performance.

To start, I'll use your questions. What is faster? depends on the actual aggregation you are performing, if you're dealing with a set operations, i.e. SUM/AVG of a column, keep it in SQL, on the other hand if you find yourself having a cursor in the procedure, move it to C#. Cursors will kill your performance! You asked if it's bad-practice to aggregate data aside and later query that repository, this is the best practice :). You'll end up with having one database catering the transactional, high-paced clients and another database storing the aggregated info, this will be quickly and easily available for your other needs. Taking it to the next step will result with you having a data warehouse, so this is definitely where you want to be heading when you have a lot information and calculations.

Lastly, caching, this is tricky and really depends on the specific nature of your needs, I'd say take the above approach, spend the time in improving the processes and I expect the end result will make caching redundant.

One of your best friends for the task is SQL Profiler, run a trace on stmt:completed to see what are the highest duration/io/cpu and pick on them first.

Good luck!

like image 152
itayw Avatar answered Nov 15 '22 05:11

itayw