i've a web api that has to deal with nearly 200 request in a second. The main job of the web api application is:
- Get the request
- Go and find the answer from cache system (redis or whatever)
- Return the result
- Send that request to azure event hub (for making some hourly calculations)
The last step needs to be done without blocking the answer. The app needs to answer fast but in the mean time it also has to send the request information to azure event hub.
Im now doing this with:
public HttpResponseMessage Post(OurDataModel dataModel) { //1 - Get answer from cache var resultData = companyFactory.GetData(dataModel); //2 - sending data to Azure Event Hub var asyncResult = Task.Run(() => new AzureEventHub().SendData(resultData)); ..... //3 return result return Request.CreateResponse((HttpStatusCode)responseType.Ok, Json(resultData ).Content); }
Azure Sender Method:
public async Task<int> SendData(MainModel data) { //Create event list --> result is List<EventData> events ... EventHubClient eventHubClient = EventHubClient.CreateFromConnectionString(connString); client.SendBatch(events); client.Close(); return 1;//I dont know what im doing code :) }
This implementation does well but not very well actually. It does what is supposed to do that is, answering so many results without delay but, lately im getting so many errors from event hubs. It says;
First Error Message Type:
The operation did not complete within the allocated time 00:00:00 for object tls0. For more information on exception types and proper exception handling, please refer to http://go.microsoft.com/fwlink/?LinkId=761101
Description: ..Exception Details: System.TimeoutException: The operation did not complete within the allocated time 00:00:00 for object tls0. For more information on exception types and proper exception handling, please refer to http://go.microsoft.com/fwlink/?LinkId=761101
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. |
Stack Trace:
|
Second Error Message Type:
The operation has timed out.
Description: ..Exception Details: System.TimeoutException: The operation has timed out.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. |
Stack Trace:
|
Strangely, it happens every 2-3 days and lasts about 10-15 mins then it goes fine again. These errors by the way
I have two questions:
Do i need to improve this implementation (Probably yes because it's like fire&forget)? Why? How?
Why im getting these errors?
I hope i made myself clear. Thank you.