-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lambda - extremely long running time fix #456
Comments
Is there any reason against using the context methods ( But, to try and fix the root problem: You mentioned running of a http server on the Lambda... I'm not familiar with Apollo's Lambda implementation but from quick glance at the source and docs, I couldn't understand what server you're talking about. Can you elaborate? @dacz |
One more thing to add. If you use Lambda and a database connection or redis connection that doesn't close that might cuase the lambda function to not respond. In the Lambda Context object there is a property More info here: http://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-context.html Hope that helps |
@soda0289 thank for your comment. I'm aware that db connection may be the problem, but because of common usage, I do not think this is the case. Even when I'll run lambda with direct SQL command, lambda finishes immediately. I'm aware about the |
@mklopets Thank for your questions. As you can see I do not use According to httpServer - I came very shortly through this lib and saw there So from my summary questions I'm still not sure about the first three. |
@soda0289 is there a recommended place to close my DB connection, as I'd like to try this method first. EDIT: Interestingly, this article (http://blog.rowanudell.com/database-connections-in-lambda/) seems to suggest leaving long-running db connections around on purpose, for efficiency. So perhaps changing the |
@Siyfion I think we should change the Lambda server to set |
@soda0289 agreed. In addition to this, it's also worth noting that adding as much of your schema generation code in the outer/global scope also will lead to much faster warm-start response times. |
Exactly as @soda0289 wrote - leaving connection open will significantly decrease lambda processing time (because if lambda stays warn the connection will be open between calls) especially if your lambda runs in VPC. For me works best the |
@dacz I think |
Agreed, I mean for general purpose Lambda functions I can see why it's off. But this is going to almost certainly contain DB calls for all users, at which point it'll just cause confusion and delay. Document it for certain, and make sure there's a way to override, but I think having it on by default is the safest course of action. |
This issue hasn't seen much in the way of reactions or additional feedback recently and there have been a number of releases in Apollo Server since this was opened, including many updates to Thanks for reporting this originally! |
Hello @dacz I am facing similar issue as yours I would like understand this better. If I keep Thank You. |
I am also seeing this same behavior. I have set |
I'm working on mid size project project with graphQL and we are working toward being fully on aws and where applicable on lambdas.
When adopting the codebase for lambda I saw strange issue. Init phase (schema parsing, db connecting etc.) of lambda was done within 400ms, the request itself was done in 400ms approx (this leaves response time for repeated requests to approx 400ms.
But I constantly saw around 11 seconds response and billed time.
I XRayed lambda, I added time logging everywhere (even in the apollo-lambda code) and everything looks like the request is processed in the supposed time but... replies were coming after 11 sec.
I mocked up lambda handler locally and - everything was fast as expected.
Out of endless experiments (with lambda these are slightly difficult because of repeated deploying and testing) I figured out the important setting:
For some reason the event loop is not empty after calling lambda callback and it takes 10+ sec to be emptied (or killed by lambda, I do not know, so far).
The setting is just telling lambda to freeze the processing after calling the callback. I tested and everything is working fine with this setting, with subsequent requests etc.
I suspect the (recommended impelmentation even by awslabs) of kind of running https server (apollo-base) that responds to the request but (maybe) keeping event loop not empty. On the other side - the errors to graphql requests are returning fast.
I'm really not sure and therefore I consider to write this issue to discuss if anyone else experiences such problem and if the solution is appropriate. As I wrote - the same codebase just wrapped in slightly different wrapper to be run as node via
apollo-graphql-server
is running smooth and fast.The wrap up:
The text was updated successfully, but these errors were encountered: