How to create many rooms (at least 100+)

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

How to create many rooms (at least 100+)

sweetmei25
2019-02-05 02:50:11

Well... I am going to buy 500 CCU or more.
I am also going to create many rooms in something like a web admin panel with a button click
There is a button "Create A New Room" in the admin panel. Each time clicking the button, a new room with a suffix will be created.
And I want to create many rooms.
Hmm... I think 1 unity instance can create only 1 room.
So, In my opinion, to create 100 rooms, I need to run 100 instances (they only creates the room and they are the master clients)
The other instances(clients) only join the room, they don't have any function to create the room themselves. If no room is available they can't join any room and need to wait until a room is empty.
I want to know how to create rooms in admin panel
Anyone who knows this please help me
I will be waiting
Thanks

Comments

JohnTube
2019-02-05 12:06:16

Hi @sweetmei25,

Why do you need an admin panel?

What you are asking for is not how Photon should be used.
Using PUN, clients create rooms.
First, the client tries to find a suitable room to join, if none was found, a new one will be created by the same client.
The client can name the rooms, of course, room names must be uniques, you can't have two rooms with the same name at the same time (for the same virtual application on the same region).
Also, clients can create as many rooms as requested.

If you really have to have an admin panel for whatever reason you will have to use a client to create rooms OR modify the server-side code for the LoadBalancing application and self-host yourself or go for Enterprise Cloud.

In any case, I repeat that what you try to do is not recommended and is not the workflow we encourage with Photon.

Also, for the public cloud, the plan is irrelevant here.
The same features are available for everyone.

sweetmei25
2019-02-05 15:06:56

Hi @JohnTube
Thanks for your kind answer.
If I need to create 100 rooms on one computer (this is the server), what is the best method to do this?
1 client can't create multiple rooms I think...
Also, launching about 100 clients on 1 server is not suitable I think...
Could you please tell me the best way?

JohnTube
2019-02-05 15:30:14

Hi @sweetmei25,

You are misunderstanding how Photon works.
PUN rooms are created on dedicated servers.
Clients do not host rooms.
So if a client creates a room, it will be created on dedicated servers and not on the client itself.
All clients connect to those same dedicated servers and communicate only via those servers, called relay servers.

sweetmei25
2019-02-05 15:39:48

Ah, I see. @JohnTube

Then is this possible?
Can I call CreateRoom function twice or more in one client?
So if I call CreateRoom function 100 times with different room name on one client, 100 different rooms will be created? (on dedicated server)

JohnTube
2019-02-05 15:54:44

Hi @sweetmei25,

When you call CreateRoom, the client will send a request to Photon Master Server first.
Photon Master Server will return a response.
If the response is successful, it will contain an address of a Photon Game Server and optionally the name of the room if the client did not specify it.
Then the client will have to disconnect from Photon Master Server and connect to that Photon Game Server.
Then the client will send a request for room creation to Photon Game Server.
If successful, the room is created and the client is joined to that room.

At this point you can't call CreateRoom any more until you leave the room, disconnect from Photon Game Server and go back to Photon Master Server.

Also, Photon rooms are cleaned up by the game server once the room becomes empty and EmptyRoomTTL expires.
You can explicitly clear events cache without waiting for players to leave.

sweetmei25
2019-02-05 16:03:47

Hi @JohnTube

Sorry for asking a lot!
But I hope that there is a way to send 100+ request for the room creation to photon server on one computer.
On 1 computer, send 100+ room creation request.
So that this computer can manage room creation and room destroying...

I am willing to buy any pricing for it.

Please let me know how to do it...

Kaiserludi
2019-02-05 16:41:42

Hi @sweetmei25.

Each client connection to the LoadBalancing application (which is what runs on Photon Cloud and also the default application for self-hosted servers) can only be active inside a single room at the same time.

Each PUN instances can only have one connection at once.

You can only run one PUN instance per Unity instance.

So yes, with PUN you would need to run a separate Unity instance for each room that you want to reside in in parallel.

However I don't think that it makes sense to run a Unity instance at all for such an admin panel, as it doesn't really need a game engine.

Hence for this admin panel I would use a Photon Realtime Client that is not integrated into Unity like PUN is, but that can run independently of it (you can still use PUN for the clients of your actual users - PUN uses realtime under the hood and PUN clients and realtime clients can interact with each other and join each others rooms, as long as they use the same appID and appVersion and connect to the same region (you need to take into consideration PUN's specific AppVersion format: {gameVersion}_{PUN_version}. So if you set the gameVersion to "1.0" in PUN and use PUN version "1.80" then the resulting AppVersion is "1.0_1.80".) ).

Just like a PUN instance one instance of the LoadBalancing Client class can only be inside one room at once.

However unlike PUN with a Realtime Client SDK you can just create multiple Client instances in one app, so you don't need your admin panel app to create a new process in the background for each room, but can just create a new instance of the Client class.

Limitations:

  • Each such connection counts as a separate CCU, so your admin panel would count as 100 CCU for billing purposes, when it resides in 100 rooms in parallel.
  • The architecture of the Photon clients is not designed for this use case and it is not tested by us. Therefor I can't really tell how well this will scale with which client SDK.

Another approach would be to use Photons async featureset. This is intended for use with asynchronous turnbased games like chess, in which not all players of a game need to be online at the same time, but one player can go online, make his turn, go offline again, then come back later to see if his opponents have made their turns. To make this kind of game possible, Photon Realtime supports it that a clients becomes inactive in a room (via opLeaveRoom(willComeBack=true)). This means the client leaves the room, but tells the server to treat it as still there, but as inactive.

Hence on a button click in your admin panel you could create a room and immediately leave it again with the willComeBack flag set to true. This way the room stays alive after the creator has left (as the creator is considered to be still there as an inactive player) and you can go on and create the next room, because you have left the previous one. This way your admin panel only needs one connection and one client instance no matter how many rooms it will open and it will only count as one CCU (however it still counts against the maxPlayers setting of each room, so you need to set the max players of a room to one player more per room than the amount of normal clients that you want to allow in it).
See https://doc.photonengine.com/en-us/realtime/current/tutorials/persistence-guide for more information on async persistent rooms.

Edit:
When thinking about this a little more it becomes apparent to me that you should definitely go with the async approach: this way when your admin panel for some reason crashes or goes offline or experiences a power outage, etc. this won't result in all rooms without normal clients in them to be closed, like it would be the case with "the admin panel always connected with one instance per room" approach.

Back to top