Here I am facing one more challenging issue and as usual turning on this site to get help.
I have one web service which performs some business logic and finally insert the result in a table. This works fine if my application is in minimal load.
Now when the load is heavy, my INSERT SQL statement got timed out. I have increased my Connection Timeout and Command Timeout. But the problem is that there are too many threads calling the same web method. Just to give some hint, my number of OPEN sql connection in heavy load is goes to 500+. FYI, I did close my connection after every command.
Now what should I do here to optimize this thing here?
I am planning to store the INSERT data in data table and store this data table in APPLICATION variable. And after every two minutes, insert the data from this datatable to database.
Do you guys have any other idea here which can smoothen my life here?
Thank you
EDIT
Here are more details ,when i run insert query in management studio
SQL Server parse and compile time:
CPU time = 0 ms, elapsed time = 0 ms.
SQL Server parse and compile time:
CPU time = 0 ms, elapsed time = 11 ms.
Table ‘IndexTable1’. Scan count 0, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table ‘IndexTable2’. Scan count 0, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table ‘fulltext_index_docidstatus_171147655’. Scan count 0, logical reads 11, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table ‘MAINTABLE‘. Scan count 0, logical reads 28, physical reads 4, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
(1 row(s) affected)
(1 row(s) affected)
SQL Server Execution Times:
CPU time = 0 ms, elapsed time = 69 ms.
SQL Server parse and compile time:
CPU time = 0 ms, elapsed time = 0 ms.
SQL Server Execution Times:
CPU time = 0 ms, elapsed time = 0 ms.
You can use a dedicated thread for inserting data into the DB. There’s no point in opening a new connection for every insert statement, when instead you can insert data in big chunks once every few seconds. This thread can run on a dedicated dispatcher or even a timer, and you can use a thread-safe queue for inter-thread communication.