Poor performance Rekognition

0

I'm running a lambda function in python that includes various opencv imports. I'm trying to use rekognition detect labels to get the bounding box dimensions of an object in an image before I crop it. The detect labels operation times out after the default lambda t/o of 3 minutes. (no other operations have taken place other than retrieving the file from s3). I've tested the detect labels operation on its own with no opncv imports using the same 41kb file and the response is under 1 sec. Are the opencv imports causing lambda performance latency? I;ve even increaed the memory up to 2048mb - no improvement.

asked 24 days ago58 views
1 Answer
0

The performance issue you're experiencing with your Lambda function using Amazon Rekognition's detect labels operation is likely not directly related to the OpenCV imports. However, there are several factors that could be contributing to the timeout:

  1. Cold starts: Lambda functions can experience longer execution times on their first invocation or after being idle for a while. This "cold start" can be more pronounced with functions that have large dependencies like OpenCV.

  2. Memory allocation: While you've increased the memory to 2048MB, this might not be the optimal configuration. Sometimes, adjusting the memory can affect CPU allocation and execution time.

  3. VPC configuration: If your Lambda function is running within a VPC, this could introduce additional latency.

  4. S3 bucket location: Ensure that the S3 bucket containing your image is in the same region as your Lambda function and Rekognition service to minimize latency.

  5. Image processing: Although you mentioned that no other operations have taken place, ensure that you're not inadvertently performing any heavy image processing before calling Rekognition.

To troubleshoot and improve performance:

  1. Use AWS X-Ray to trace your Lambda function and identify where the bottleneck is occurring.

  2. Consider using provisioned concurrency to keep your function warm and reduce cold start times.

  3. Try different memory configurations to find the optimal setting for your function.

  4. If possible, pass the image bytes directly to Rekognition instead of referencing the S3 object, as this can be faster for near real-time processing.

  5. Ensure you're handling errors properly in your code, especially for cases where Rekognition might not detect any labels or faces in the image.

  6. If the issue persists, you might want to consider splitting your function into two: one for OpenCV operations and another for Rekognition operations, to isolate the performance impact.

Remember, the fact that the Rekognition operation works quickly when tested independently suggests that the issue likely lies within your Lambda function configuration or code structure rather than with Rekognition itself.
Sources
Amazon Rekognition Image operation latency - Amazon Rekognition
Lambda function time execution | AWS re:Post
Lambda has performance issue | AWS re:Post

profile picture
answered 24 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions