I use Google App Engine Java for over a year. Trying write a simple strategy game. Unfortunately current solution does not satisfy me. My experience with GAE is even insufficient.
My problem is to simulate a battle at a specific time, which shall be calculated in the task queue.
Current solution:
I have entities in Datastore : BattleInfo ( field: battleID, startTime, userA, userB)
I have prepared two servlets: BattleInitServlet and BattleServlet.
BattleInitServlet - execute the query to the datastore and loads BattleInfo. Tasks are added to the battle-queue:
Queue queue = QueueFactory.getQueue("battle-queue");
...
for(BattleInfo i : list){
long countdownMillis = i.getStartTime() - currentTime;
queue.add(TaskOptions.Builder.withUrl("/battle").param("battleID", i.getBattleID()).method(TaskOptions.Method.POST).countdownMillis(countdownMillis));
}
BattleServlet - task will start at a specific time. I receive BattleInfo from the battleID and loads the required data. Simulates the battle and save to datastore.
BattleInitServlet is executed every 30 minutes using cron.
With a few simulation , result is OK. Tests with a large amount of simulation, task queue is clogged. I can solve this by changing the settings Queue, but I increase costs, and does not solve the problem. I do not know how to speed up and optimize.
I tested the pipeline API that works fast. The problem is that the pipeline API initiates a moment and executed tasks immediately .
I want to prepare a pipeline using tasks that runs in the background and executed the battle for a specified time and simulates it. Just don't know how to write it using GAE and tasks.
Has anyone had a similar problem?
Please help me. Thank you.