2

I use AmazonDynamoDBClient in the lambda to remove/insert an item into the dynamodb once the message arrives into the queue. Here is the code for delete operation

    var request = new DeleteItemRequest()
                {
                    TableName = _tableName,
                    Key = new Dictionary<string, AttributeValue>()
                    {
                        { "Id", new AttributeValue() { S = id } }
                    }
                };
                await _client.DeleteItemAsync(request);

_client is set up as singleton in my DI container as well as the repository class communicating with dynamodb.

During load tests (around 1000 messages for 1 minute), it was found out that sometimes I might receive an exception SSLStream: ObjectDisposedException

One or more errors occurred. (Cannot access a disposed object.
Object name: 'System.Net.Sockets.NetworkStream'.) (Cannot access a disposed object.
Object name: 'SslStream'.) (Cannot access a disposed object.
Object name: 'SslStream'.) (Cannot access a disposed object.
Object name: 'SslStream'.) (Cannot access a disposed object.
Object name: 'SslStream'.) ---> System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.Sockets.NetworkStream'.
   at Amazon.Runtime.HttpWebRequestMessage.GetResponseAsync(CancellationToken cancellationToken)
   at Amazon.Runtime.Internal.HttpHandler`1.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.Unmarshaller.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.EndpointDiscoveryHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.EndpointDiscoveryHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.CredentialsRetriever.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.ErrorCallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.MetricsHandler.InvokeAsync[T](IExecutionContext executionContext)
   at MyLambda.Repository.........

The same issue for insert btw

I watched at DynamoDb metrics: latency is really low (10ms) and no errors. Is there anything I can try to do regarding this to fix the issue and avoid such errors?

1 Answer 1

3

After a thorough investigation, I found that the root cause of this issue is lambda MemorySize settings. I made an experiment with different MemorySize and got the following results:

  • 128Mb - lot's of SSLStream: ObjectDisposedException
  • 256Mb - noticeably a fewer exceptions
  • 512Mb - no exceptions

For each case memory used by the application wasn't higher than 110Mb.

As a result of this, I came into the next conclusion: As AWS distributes CPU resources to each lambda depending on allocated memory, it means that I/O operations and network traffic might also be affected by those setting.

Here are several blog posts confirming my thoughts:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.