-1

Hi I need make a global variable on google app engine (on python). I need a counter to count the request on a freemium api (I have to pay if go over 2000 request at month), but for testing I don't want pay, so if the global variable is equal to the limit I want to stop calling the api. Is there a way? maybe there is an elegant mode to do, (I was thinking to a line on the datastore). If you can put an example I will be happy.

Salil Agarwal
  • 525
  • 1
  • 3
  • 12
  • this is a bit too broad as a stack overflow question (we prefer questions with a specific problem, like "I tried to do a counter in the datastore, but I now have contention issues, here is my code" to "how do I do X". In any case, you should look into sharded counters https://cloud.google.com/appengine/articles/sharding_counters – Patrice Jul 07 '15 at 15:39

1 Answers1

1

App Engine frontends themselves are stateless so you need to persist state to something like Datastore. (You could use Memcache, but it will probably be evicted and your counter will be reset.)

However, if you will be incrementing your counter at a rate of more than ~1/s then you will need to look at a sharded counter: article | example implementation

tx802
  • 3,524
  • 2
  • 17
  • 22