Sql-server – Slow fill database

csql server

The source sends in my program a large number of rows. When the number of rows such as two thousand per minute for one table, all is saved in the database properly. But if you send two thousand per minute to 200 tables, then there is a delay. Sometimes a big delay, in five minutes. How can I make it so that all the information was entered on time. How to parallelize? Or any other ways out of the situation?

Example:

  1. send request
  2. get response

Code:

void feed_response(int requestId, string copmanyname, string someinformation)
 {
   SQL.sendToSQL(int id, string copmanyname, string someinformation);
 }
  1. sql.sendtosql

Code:

public static void sendToSQL(int id, string copmanyname, string someinformation)
 {
  SqlCommand commandTradeToDb = new SqlCommand("INSERT INTO dbo."+ copmanyname.ToUpper() +" (id, someinformation) VALUES (@id, @someinformation)", connection);

  commandTradeToDb.Parameters.Add("@id", id);
  commandTradeToDb.Parameters.Add("@someinformation", someinformation);
 }

Code is very simply.

ps Variables in a method sql.sendToSql changed.

Best Answer

When you are sending 2000 requests to the same table, SQL Server already has the pertinent pages in memory i.e. SQL Server caches data pages in memory so they don't have to be read in from disk next time. When you are writing to multiple tables, SQL has to read data pages in each of those tables to find the correct spot to insert new rows. Unless you have enough memory allocated to SQL SErver, this will push out data pages that have been previously cached.

To get around this, you could group all the inserts for each particular table and execute them in sequence. You could also add memory to the server, giving it a larger cache to work with.