Should I do fast asynchronous mode if the method is already asynchronous

I have this code (non-essential information that it runs on EC2 instances in AWS, processing messages in the SQS queue).

The first statement in the method receives some data via http, the second statement saves the state in the local dynamo data warehouse.

public bool HandleMessage(OrderAcceptedMessage message)
{
    var order = _orderHttpClient.GetById(message.OrderId);
    _localDynamoRepo.SaveAcceptedOrder(message, order);
    return true;
}

Performance characteristics are that a round trip is 100-200 milliseconds, and a dynamo record is about 10 milliseconds.

Both of these operations have versions async. We could write it as follows:

public async Task<bool> HandleMessage(OrderAcceptedMessage message)
{
    var order = await _orderHttpClient.GetByIdAsync(message.OrderId);
    await _localDynamoRepo.SaveAcceptedOrderAsync(message, order);
    return true;
}

So the guide is that since the first operation "may take more than 50 milliseconds to complete," it should use async and wait. (1)

, ? :

: 50 .

async: . , , .

1) http://blog.stephencleary.com/2013/04/ui-guidelines-for-async.html

+4
4

, EC2 AWS, SQS

, , . ; .

, , " 50 "

. , 50 .

- . . 50 - . async .

, /? , async, . - . , -.

+5

, , - async - . , . , , async.

. 200- HTTP- - ( , , ).

50 . .

latency times frequency. , . .

100 10 . . , , , .

, , , , .

.

+1

... . tl; dr: , async.

, , :

var order = await _orderHttpClient.GetByIdAsync(message.OrderId).ConfigureAwait(false);
await _localDynamoRepo.SaveAcceptedOrderAsync(message, order).ConfigureAwait(false);

: await ed , , . , - SaveAcceptedOrder(), . , async ( IO bound = "async by design" ). IO, .

+1

If you make any remote call, make it asynchronous. Yes, DynamoDB calls are quick (unless one has a sub-pair hash key or many gigabytes of data in one table), but you still make them over the Internet (even if you are inside AWS EC2, etc. e.), and therefore you should not ignore any of the Eight Fallasies Distributed Computing - and especially not 1) The network is reliable or 2) The delay is zero.

+1
source

All Articles