I want to develop clock based strategy game.
In my game, after the user did their move worker should grab speed data from Durable Objects and target location from the user then calculate the user’s next location and send it to all closed players.
Is that possible? What can be clock time? (I’m not expecting 20 cycle calculation per second)
Can I extend? My game’s features? With other workers I mean is it possible to connect one durable object with other scheduled workers?
For example other workers might be handle collecting items on the ground. While user moving.
And how many does this cost me? What do you think? for;
0.0.1 version: 1 durable object share users location and speeds and connected 100 user same time.
I think to implement this clocked-based feature I need a clock Might be scheduled workers solve this problem. What is the highest frequency of that? is 1 second possible? If the scheduled worker connects 1 durable object and sends 100 users’ new location per sec. How much does it cost me?
BTW, this architecture is really great. I also extend the game’s features without decreasing the performance with another worker (If connected workers don’t effect much of course… Does that?)
Clock time is the standard time from when a worker starts. There is always CPU which is consumed when running CPU tasks, the example given is that if you are fetching something from an external site then while you wait for a response your CPU time doesn’t increase but your clock time does.
The quickest you can trigger a cron worker is one minute. You can also look at durable object alarms as they trigger directly from the object and not the worker.
I want to move core game logic into scheduled workers to distribute the CPU power. Seems I have to do these things on the connected WebSocket workers.
Do you have any idea about the cost of these kinds socket workers? for example;
100 clients connected 1 durable object and 1 worker continuously sending and receiving data; Also 100 clients must know each other to do that durable object will be high pressure: how much does it cost?
and, Is that a good idea to use Cloudflare for that or should I just continue with ec2?
If I was doing something like this, I would also be using websockets and durable objects. There is no cost at this time for websockets on Cloudflare so the largest cost is probably going to be the durable object being active in the first place.
The way it’s priced is in GB seconds. Included in the bundled plan is 400,000 GB seconds. Each durable object is 128MB of ram usage. Which means for an entire month (2628003 seconds) if a single durable object is active would cost
2,628,003 seconds * 0.128 GB = 336,384 GB-s
So if a single durable object is active for the month you wouldn’t have any charge at all for the activeness. The charge would be for the requests to the durable object. That would largely depend on your game and how it’s designed. But the cost would be significantly less than what you would pay if you were running a server. A million requests to the object is just $0.15 after the first million bundled in.
By using websockets you can make a single request to the durable object be sent to every single connected client by broadcasting the message. If you want coordination between all the clients that’s how you do it as cheap as possible. Sending websockets cost nothing.
Of course this doesn’t account for the amount of state changes to your durable object you would be making. Per game start I would design to just have a single game state to be updated and broadcast changes to all clients. Every action in the game would be sequential and you can store it into the object with a time to make sure things stay that way.
Overall a lot of the guess work is taken out of the equation. You don’t need to wonder about the coordination or states becoming invalid or failing. It just works on the edge. Fast (really fast) and cheap.
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.