Customization
I have a web service that takes its inputs through a REST interface. A REST call does not return any meaningful data, so everything that is passed to the web service is written only to the database, and thatβs all. This is the analytics service that my company uses to internally process special requests for web requests that are received on their web page. Therefore, it is very important that the response takes as little time as possible in order to return as much as possible.
I have optimized the code as much as possible to make the answer as fast as possible. However, the time that the database remains open continues to open the connection longer than I want before the response is sent back to the web client.
This code looks basically like that, by the way, this is ASP.NET MVC, using the Entity Framework running on IIS 7, if that matters.
public ActionResult Add() {
using (var db = new Entities()) {
var log = new Log {
}
db.AddToLogs(log);
db.SaveChanges();
}
return File(pixelImage, "image/gif");
}
Question
Is there a way to disable database loading in another process, so the response to the client returns almost instantly?
I was thinking of packing everything in a block usingin another thread to make the database insert asynchronous, but I don't know if this was the best way to free the response back to the client.
What would you advise if you tried to achieve this goal?
source
share