Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Elastic Beanstalk Worker timing out after inactivity during long computation

I am trying to use Amazon Elastic Beanstalk to run a very long numerical simulation - up to 20 hours. The code works beautifully when I tell it to do a short, 20 second simulation. However, when running a longer one, I get the error "The following instances have not responded in the allowed command timeout time (they might still finish eventually on their own)".

After browsing the web, it seems to me that the issue is that Elastic Beanstalk allows worker processes to run for 30 minutes at most, and then they time out because the instance has not responded (i.e. finished the simulation). The solution some have proposed is to send a message every 30 seconds or so that "pings" Elastic Beanstalk, letting it know that the simulation is going well so it doesn't time out, which would let me run a long worker process. So I have a few questions:

  1. Is this the correct approach?
  2. If so, what code or configuration would I add to the project to make it stop terminating early?
  3. If not, how can I smoothly run a 12+ hour simulation on AWS or more generally, the cloud?

Add on information Thank you for the feedback, Rohit. To give some more information, I'm using Python with Flask.

• I am indeed using an Elastic Beanstalk worker tier with SQS queues

• In my code, I'm running a simulation of variable length - from as short as 20 seconds to as long as 20 hours. 99% of the work that Elastic Beanstalk does is running the simulation. The other 1% involves saving results, sending emails, etc.

• The simulation itself involves using generating many random numbers and working with objects that I defined. I use numpy heavily here.

Let me know if I can provide any more information. I really appreciate the help :)

like image 423
Christian Avatar asked Sep 30 '22 10:09

Christian


2 Answers

After talking to a friend who's more in the know about this stuff than me, I solved the problem. It's a little sketchy, but got the job done. For future reference, here is an outline of what I did:

1) Wrote a main script that used Amazon's boto library to connect to my SQS queue. Wrote an infinite while loop to poll the queue every 60 seconds. When there's a message on the queue, run a simulation and then continue through with the loop

2) Borrowed a beautiful /etc/init.d/ template to run my script as a daemon (http://blog.scphillips.com/2013/07/getting-a-python-script-to-run-in-the-background-as-a-service-on-boot/)

3) Made my main script and the script in (2) executable

4) Set up a cron job to make sure the script would start back up if it failed.

Once again, thank you Rohit for taking the time to help me out. I'm glad I still got to use Amazon even though Elastic Beanstalk wasn't the right tool for the job

like image 65
Christian Avatar answered Oct 20 '22 15:10

Christian


From your question it seems you are running into launches timing out because some commands during launch that run on your instance take more than 30 minutes. As explained here, you can adjust the Timeout option in the aws:elasticbeanstalk:command namespace. This can have values between 1 and 1800. This means if your commands finish within 30 minutes you won't see this error. The commands might eventually finish as the error message says but since Elastic Beanstalk has not received a response within the specified period it does not know what is going on your instance.

It would be helpful if you could add more details about your usecase. What commands you are running during startup? Apparently you are using ebextensions to launch commands which take a long time. Is it possible to run those commands in the background or do you need these commands to run during server startup?

If you are running a Tomcat web app you could also use something like servlet init method to run app bootstrapping code. This code can take however long it needs without giving you this error message.

like image 24
Rohit Banga Avatar answered Oct 20 '22 17:10

Rohit Banga