0

I am stress testing my backend right now and it seems when I do a lot of calls in a short period of time I hit the threads limit in lambda and get the following error:

"errorMessage":"unable to create new native thread","errorType":"java.lang.OutOfMemoryError

Currently my architecture is like so:

(API Gateway) -> (Lambda) -> (DynamoDB)

I figure the best way to avoid the above problem is to implement queuing. I have read online that this can be done a bunch of different ways, namely through SNS, SQS, and Kinesis. Which of these will:

A) Fit best into my current architecture requiring the least integration?

B) And be able to solve my threading problem?

C) Why?

Thanks

sometimesiwritecode
  • 2,993
  • 7
  • 31
  • 69
  • How much memory have you configures on your Lambda function? Are you running at the maximum of 1536MB? The JMV does not have enough free memory available to create a new thread. – hellomichibye Sep 16 '16 at 19:58
  • I thought at first this was the issue so i bumped my memory limit from 512mb to 1024mb and it didn't seem to change a thing. Thoughts? @hellomichibye – sometimesiwritecode Sep 16 '16 at 20:40
  • I will not comment further on this, since I have [already mentioned](http://stackoverflow.com/q/39500938/1695906) the probable explanation and got no reaction -- your container is being reused and you aren't cleaning things up properly. This is the only logical explanation why you would have the problem only when you have multiple invocations in a short period of time. – Michael - sqlbot Sep 17 '16 at 00:17
  • @Michael-sqlbot I honestly don't think it is due to a lack of memory/going over the memory limit because I have confirmed in the logs no specific invocation is anywhere my limit, which I have set at 1024mb. Perhaps you are right though, I just don't know how to confirm that. Furthermore, I don't know how to clean up after myself beyond setting object references to null, which I am already doing... – sometimesiwritecode Sep 17 '16 at 01:51
  • I commented on the original question. Make GeoDataManagerConfiguration static or you create a threadpool for every lambda invocation. – hellomichibye Sep 17 '16 at 17:47
  • @hellomichibye im confused as to how I make my GeoDataManagerConfiguration static and how this fixes the problem - link you provided didn't explain it too me. any ideas? – sometimesiwritecode Sep 18 '16 at 01:45
  • @majorcoder move this line GeoDataManagerConfiguration config = new GeoDataManagerConfiguration(ddb, "geo"); out of the method and place it right under the class and add the static keyword to it. Like static GeoDataManagerConfiguration config = new GeoDataManagerConfiguration(ddb, "geo"); – hellomichibye Sep 18 '16 at 10:24
  • @hellomichibye thanks I will try this solution and if it works will accept your answer – sometimesiwritecode Sep 18 '16 at 18:08

1 Answers1

0

SNS isn't a queue. SQS isn't integrated with Lambda at all. Kinesis is probably the best option in this scenario.

Mark B
  • 183,023
  • 24
  • 297
  • 295
  • Ok - Kinesis looks fine but in the documentation (http://docs.aws.amazon.com/lambda/latest/dg/with-kinesis.html) I don't notice any mention of API gateway. Will the fact that im using api gateway matter/complicate integration or is it the same? – sometimesiwritecode Sep 16 '16 at 19:03