Creating rooms on server ready !

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

User avatar
faisal007
Posts: 37
Joined: 27 Sep 2016, 09:01

Creating rooms on server ready !

Postby faisal007 » 15 Jun 2017, 11:20

Hello,

I wanted to create 500 rooms at server boot, however server is crashing by doing so. That's why I m creating 100 rooms after every 1 minute but after 3 or 4 db calls, I m getting this error:

java.lang.OutOfMemoryError: PermGen space

Any suggestions ? or whats the best way to achieve this task ?

Here is my code:

Code: Select all

private void CreateRooms() throws SFSCreateRoomException
   {
      try
      {
         ISFSArray resRoom = dbManager.executeQuery("{call get_all_rooms(" + roomsRecordOffset + ")}",  new Object[]{});
         
         GenericCreateRoom(resRoom);
         
         if(resRoom.size() > 0)
         {
            new java.util.Timer().schedule(
                    new java.util.TimerTask() {
                        @Override
                        public void run() {
                           trace("Create more rooms");
                           /*try
                           {
                           ISFSArray resRoom = dbManager.executeQuery("{call get_all_rooms(" + roomsRecordOffset + ")}",  new Object[]{});
                           trace("In create more rooms " + resRoom.size());
                        }
                           catch (SQLException e)
                        {
                           // TODO Auto-generated catch block
                           e.printStackTrace();
                        }*/
                           
                           try
                           {
                              roomsRecordOffset += 200;
                              CreateRooms();
                        }
                           catch (SFSCreateRoomException e)
                           {
                           e.printStackTrace();
                        }
                        }
                    },
                    60000
                  );
         }
         else
         {
            new java.util.Timer().schedule(
                    new java.util.TimerTask() {
                        @Override
                        public void run() {
                           trace("No rooms to create");
                           roomsRecordOffset = 0;
                        SetRefreshScheduleTimerValue();
                        }
                    },
                    60000
                  );
            
         }
         
      }
      catch (SQLException e)
      {
         trace(ExtensionLogLevel.WARN, "SQL Failed: " + e.toString());
      }
      
   }
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Creating rooms on server ready !

Postby Lapo » 15 Jun 2017, 13:24

hi,
even if you didn't mention it, I think you're creating Rooms with an attached Extension.
I also think such Extension is probably pretty big (i.e. it loads quite a bit of jar files / dependencies) and that causes the PermGen error.

I'd recommend to read this:
http://smartfoxserver.com/blog/performa ... xtensions/

Hope it helps
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
faisal007
Posts: 37
Joined: 27 Sep 2016, 09:01

Re: Creating rooms on server ready !

Postby faisal007 » 16 Jun 2017, 06:16

Yes I m attaching extensions dynamically and NO i m not using dependencies files right now, I have compiled everything in the same jar as explained below.

Yes, I came through this link and now implementing the suggested solutions.

However, I have a question:

Currently I have 3 rooms extensions, PokerRoomExtension.jar, PokerSitNGoExtension.jar, PokerShootoutExtension.jar.

Only game joining and winning rules are different, rest classes are same, but I have deployed them in a single package in all three extensions. Meaning that all three extensions contains the shared classes which logically and ideally be somewhere in a shared folder. But now I have developed the game and its almost impossible for me to change the architecture.

That said, now at the moment "Dependency check" approach is not feasible for me to implement. So I m implementing approach mentioned in this section "Alternative deployment method":

My question is should I deploy all three .jar files in "extension/__lib__/" folder ? and remove them from "extension" folder ?

Also I m creating dynamic rooms and attaching extension dynamically. So that code would be same ?

Code: Select all

if(res.getSFSObject(i).getUtfString("room_type").equalsIgnoreCase("tournament"))
         {
            tournamentRoEx = new RoomExtensionSettings("PokerSitNGoExtension", "com.ext.GameExtension");
            crs.setExtension(tournamentRoEx);
            crs.setGroupId("TournamentRoom");
         }
         else
         {
            roEx = new RoomExtensionSettings("PokerRoomExtension", "com.ext.GameExtension");
            crs.setExtension(roEx);
            crs.setGroupId("NormalRoom");
         }
Last edited by faisal007 on 16 Jun 2017, 07:14, edited 2 times in total.
User avatar
faisal007
Posts: 37
Joined: 27 Sep 2016, 09:01

Re: Creating rooms on server ready !

Postby faisal007 » 16 Jun 2017, 06:51

By doing the alternative method, I m getting this error and unable to attach extension with rooms dynamically,

Code: Select all

com.smartfoxserver.v2.exceptions.SFSExtensionException:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Exception: com.smartfoxserver.v2.exceptions.SFSExtensionException
Message: Extension boot error. The provided path is not a directory: extensions/PokerRoomExtension
Description: Failure while creating room extension.
Possible Causes: If the CreateRoom request was sent from client make sure that the extension name matches the name of an existing extension
+--- --- ---+
Stack Trace:
+--- --- ---+
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.createJavaExtension(SFSExtensionManager.java:346)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.createExtension(SFSExtensionManager.java:260)
com.smartfoxserver.v2.entities.managers.SFSRoomManager.createRoomExtension(SFSRoomManager.java:259)
com.smartfoxserver.v2.entities.managers.SFSRoomManager.createRoom(SFSRoomManager.java:211)
com.smartfoxserver.v2.entities.SFSZone.createRoom(SFSZone.java:247)
com.smartfoxserver.v2.api.SFSApi.createRoom(SFSApi.java:727)
com.smartfoxserver.v2.api.SFSApi.createRoom(SFSApi.java:697)
ServerReadyHandler.GenericCreateRoom(ServerReadyHandler.java:199)
ServerReadyHandler.CreateRooms(ServerReadyHandler.java:98)
ServerReadyHandler.handleServerEvent(ServerReadyHandler.java:41)
com.smartfoxserver.v2.extensions.SFSExtension.handleServerEvent(SFSExtension.java:258)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.dispatchEvent(SFSExtensionManager.java:769)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.dispatchGlobalEvent(SFSExtensionManager.java:670)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.dispatchEvent(SFSExtensionManager.java:638)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.handleServerEvent(SFSExtensionManager.java:884)
com.smartfoxserver.v2.core.SFSEventManager$SFSEventRunner.run(SFSEventManager.java:63)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Creating rooms on server ready !

Postby Lapo » 16 Jun 2017, 09:33

faisal007 wrote:Yes I m attaching extensions dynamically and NO i m not using dependencies files right now, I have compiled everything in the same jar as explained below.

Well, it's the same thing. You're duplicating all the dependencies for every Extension thus using too much memory.
Make sure to deploy the dependencies under extensions/__lib__/ this will save you a lot of memory.


Only game joining and winning rules are different, rest classes are same, but I have deployed them in a single package in all three extensions. Meaning that all three extensions contains the shared classes which logically and ideally be somewhere in a shared folder. But now I have developed the game and its almost impossible for me to change the architecture.

I don't think you need to change it.
This approach is correct. What the article suggests is to move the dependencies (i.e. the external jars/libraries) to the __lib__ folder.
Also, it goes without saying, make sure not to package the sfs2x.jar and sfs2x-core.jar libraries in your final jar. Those are just for development and must not be included in the deployment jar.

My question is should I deploy all three .jar files in "extension/__lib__/" folder ? and remove them from "extension" folder ?

Yes, that's also an option, if the above fails to solve the problem.

Also I m creating dynamic rooms and attaching extension dynamically. So that code would be same ?

Code: Select all

if(res.getSFSObject(i).getUtfString("room_type").equalsIgnoreCase("tournament"))
         {
            tournamentRoEx = new RoomExtensionSettings("PokerSitNGoExtension", "com.ext.GameExtension");
            crs.setExtension(tournamentRoEx);
            crs.setGroupId("TournamentRoom");
         }
         else
         {
            roEx = new RoomExtensionSettings("PokerRoomExtension", "com.ext.GameExtension");
            crs.setExtension(roEx);
            crs.setGroupId("NormalRoom");
         }


Yes same code, only you will change the folder name from the current on to __lib__

cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
faisal007
Posts: 37
Joined: 27 Sep 2016, 09:01

Re: Creating rooms on server ready !

Postby faisal007 » 20 Jun 2017, 05:44

Alright, thanks for the details reply.

Right now, I have increased Heap memory size and the problem is solved, but this is a temporary fix.

Now, I m separating libraries and also removing sfs2x-core.jar and sfs2x.jar to make sure these will not be there in final jar.

Thanks.
User avatar
faisal007
Posts: 37
Joined: 27 Sep 2016, 09:01

Re: Creating rooms on server ready !

Postby faisal007 » 20 Jun 2017, 05:54

One more question:

PFA,

External libraries/jars I have added while developing extension in Flash builder, Should I remove all of them before export and put all of them in _lib_folder on my server where sfs2x is installed ?

Also, do you have any idea about Order and Export tab in other screenshot ?

Thanks.
Attachments
Libraries.png
libraries/jars I have added while developing extension in Flash builder
(73.01 KiB) Not downloaded yet
Export.png
Order and Export tab
(58.48 KiB) Not downloaded yet
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Creating rooms on server ready !

Postby Lapo » 20 Jun 2017, 07:13

Here's a simple rule to organize your exported jar files:

1-> Any dependency that comes from SFS2X doesn't need to be deployed (because it's already in the main SFS2X/lib/ folder)
2-> All other jar dependencies should not be packed in the Extension jar. They should be deployed under SFS2X/extensions/__lib__/

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
faisal007
Posts: 37
Joined: 27 Sep 2016, 09:01

Re: Creating rooms on server ready !

Postby faisal007 » 20 Jun 2017, 09:13

Alright, Is there a way to check if these dependencies are packed with Extension.jar ? Because I have changed .jar to.zip and than extract to see, only classes are there and no sfs2x.jar and sfs2x-core.jar found.
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Creating rooms on server ready !

Postby Lapo » 20 Jun 2017, 09:47

Most Java IDEs such as Eclipse and IDEA allow you to see what's inside a jar file, otherwise you can open it with a zip utility.
A .jar file is just a zip file with a different extension name.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
faisal007
Posts: 37
Joined: 27 Sep 2016, 09:01

Re: Creating rooms on server ready !

Postby faisal007 » 20 Jun 2017, 10:10

Alright, confirmed no .jar's are packed. Thanks.

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 61 guests