0

I have a program that after some computation( at leat 5 per second) I get a result for any of them. I want to save these data to corresponding table in data base. My program written with c# and I use entity framework code first and wpf. My program is similar below code:

public struct ResultData{

 //Contain some result for example 20 property of string, int and float
}

public class MyProcess
{
    public void GetResult(){
       //some computation
       ....
       return resultdata;
    }
}

public class MainClass{

   public MyPorccess porcess;


   public ResultData newResultData; 
   ...

   //below section occurs 10 per second
   {
      ...
      newResultData = process.GetResult;

      //save to database
      using(sampledatabse db= new sampledatabse()){
         ...
         //add new result to database
         db.SaveChanges();
      }
      ....       
}

What is best practice for save these result into database with best performance in programs that need save many record per second?

What is least time of for example 10 operation per second into database?

Usage of my ram In current program with save new result into database after get new result, increase ascending.

please help me.

Edit: I create a concurrentQueue and enqueue new result to it. Then I create a backgroundWorker and inside it I dequeue resultData when ConcurrentQueue.Length is bigger than 0. Then I save this new result to database.
But ram usage is ascending.

  • _"best practice"_ is probably subject to opinion. Besides, it's impossible to tell without knowing how many tables; columns; indexes and **infrastructure** etc are involved. [ask] –  Dec 21 '17 at 03:34
  • Why dont you just try and see if it saves in under 1 second? If it does not then figure out which part is taking long (bottleneck) and then try and improve that part. If you need help then ask about that part specifically because then you will have more details. – CodingYoshi Dec 21 '17 at 03:36
  • @hassanmohagheghiyan have you analyze the area where ram is climbing in your application? – programtreasures Dec 21 '17 at 04:08
  • When I comment enqueue and backgroundWorker ram usage is not ascending. – Hassan Mohagheghian Dec 21 '17 at 04:10
  • this post possible help https://stackoverflow.com/questions/5940225/fastest-way-of-inserting-in-entity-framework – yu yang Jian Dec 21 '17 at 06:33

1 Answers1

2

To avoid multiple db calls here in your case there is 10 per second, to my opinion you can use Queue to insert the data.

You can Enqueue your objects which you wanted to be insert,

Create one timer which Dequeue your objects in some interval and bulk insert to db.

programtreasures
  • 4,250
  • 1
  • 10
  • 29