ThePiachu
ThePiachu

Reputation: 9185

GAE Golang - how to configure a backend to be doing a task every X seconds?

In my Google App Engine Go application I need to perform a task every 5-10 seconds. I understand that using the standard Cron won't work, since that can only schedule tasks every minute. Similarly, sleeping in a thread like that might not be the best option. To the best of my knowledge, I need to use some backend instances to perform those tasks.

How do I configure my app to handle such tasks in a timely and resource-efficient fashion? Do I just run the backend 24/7 and tick away until I need to do something, or is there some more efficient way to perform a task and then schedule another task to run in 5-10 seconds?

Upvotes: 1

Views: 427

Answers (1)

Martin Berends
Martin Berends

Reputation: 4178

This question highlights a tension between processing efficiency and quality of service (timing accuracy). The most efficient approach is a Task Queue (Push Queue style) using Delay or ETA options but the API offers no Service Level Agreement about accuracy. The most accurate approach is the 24/7 backend you described but its overheads are much higher [Edit - and AppEngine does not guarantee its uptime].

My experience with a Java based Push Queue is that over 90% of tasks execute within 2 seconds of the scheduled time and that under 1% of tasks start more than 10 seconds late. No tasks ever seem to run early.

Edit - as Zig points out from experience, AppEngine may shut down a backend at any time and provides no automatic way to restart it. Thus the promptness of a backend is spoiled by unpredictable spells of downtime.

In summary Task Queues are efficient and reliable but less timely than backends which are more costly and less reliable. Use Task Queues rather than backends in most cases.

Upvotes: 2

Related Questions