简体   繁体   中英

How to keep an App Engine/Java app running with deaf requests from a Java/Python web cron?

  1. App Engine allows you 30 seconds to load your application
  2. My application takes around 30 seconds - sometimes more, sometimes less. I don't know how to fix this.
  3. If the app is idle (does not receive a request for a while), it needs to be re-loaded.

So, to avoid the app needing to be reloaded, I want to simulate user activity by pinging the app every so often.

But there's a catch . . .

If I ping the app and it has already been unloaded by App Engine, my web request will be the first request to the app and the app will try to reload. This could take longer than 30 seconds and exceed the loading time limit.

So my idea is to ping the app but not wait for the response. I have simulated this manually by going to the site from a browser, making the request and immediately closing the browser - it seems to keep the app alive.

Any suggestions for a good way to do this in a Python or Java web cron (I'm assuming a Python solution will be simpler)?

使用App Engine内置cron可能更容易使应用程序保持活动状态。

I think what you want is just:

import httplib
hcon = httplib.HTTPConnection("foo.appspot.com")
hcon.request("GET", "/someURL")
hcon.close()

the simplest Java http pinger:

URLConnection hcon = new URL("http://www.google.com").openConnection();
hcon.connect();
hcon.getInputStream().read();

App engine also has a new PAY feature where you can have it "always-on". Costs about $0.30 USD cents a day. Just go into your billing settings and enable it if you don't mind paying for the feature. I believe it guarantees you at least 3 instances always running.

(I didn't realize hitting a /ping url which caused an instance to spin up would cause it to exceed the 30 sec limit!)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM