I have written C# Job to read from IIS line by line and create the JSON and post the data to DB.The Job is reading 45K lines and inserts operations are very slow. I enabled the parallel programming in job but still the performance was very slow. It took almost 2 Hours to complete the operation.
Here is my code snippet for calling the API:
Parallel.For(0, logV.Count, counter =>
{
Console.WriteLine(JsonConvert.SerializeObject(logV[counter]));
var URL = WebConfigurationManager.AppSettings["URL"];
var client = new RestClient(URL);
var request = new RestRequest(Method.POST);
request.AddHeader("content-type", "application/json");
request.AddHeader("Authorization", "Basic TEST");
request.AddParameter("application/json", JsonConvert.SerializeObject(logV[counter]), ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Console.WriteLine("Lines read" + counter);
});
Here is my API:
// POST: api/IISLogs
public async Task<IHttpActionResult> Post(IISLog iislog)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
db.IISLogs.Add(iislog);
await db.SaveChangesAsync();
return CreatedAtRoute("DefaultApi", new { id = iislog.Id }, iislog);
}
How can i do multiple inserts in Database using single HTTPS POST Opertaion or how can i convert the method as Batching?