Performance and Optimization
From EsWiki
Contents |
Adjusting ElectroServer's Memory
ElectroServer is a Java application. All Java applications run inside of a "virtual machine". This virtual machine is very gracious of your computer and won't allow any application inside of it to take too much memory by default. ElectroServer can need more memory than the default 64 megabytes that's available as you start to get into higher-load environments. Because of this, you need to tell the virtual machine that it's OK for it to use more memory. This is done via a command-line switch. Specifically:
-Xmx<amount>M
For even more memory, you can specify the amount in gigabytes:
-Xmx<amount>G
Simply replace the <amount> with the number of megabytes (or gigabytes) you want to make available. ElectroServer will use this as the maximum available and will not exceed it. See Java application launcher, non-standard options for more details.
The following sections cover how to adjust memory on different operating systems and environments.
Windows
Executable
If you are running the server as a stand-alone instance, the easiest way to set the command-line parameter is to create a "batch" file. This is a file that Windows can use to run programs with settings.
- Shut down ElectroServer if it is currently running.
- Navigate to the server installation folder. This is the folder you chose when you installed the server.
- Right-click within the folder, choose "New" and then choose "Text Document".
- Name the file "Start.bat" and say "Yes" when Windows asks you about changing the file extension.
- Right click on your new file and choose "Edit".
- Place the following two lines in your file:
<type> -J-Xmx<amount>M pause
- Replace <type> with the name of the executable you use for the server. It might be ElectroServer, RegistryServer, or GatewayServer depending on which you installed.
- Replace <amount> with the amount of memory you want to use.
- That's it! Now when you want to support the increased memory you just need to run "Start.bat" when you want to start the server.
Here's a specific example, asking for 1024 megabytes and using the standalone server:
ElectroServer -J-Xmx1024M pause
An alternate (but more complicated) batch file that also works is:
title "My ES4 Server" cd server java -Xmx2G -jar lib\ElectroServer4-bootstrap.jar -mode StandAlone -config config\ES4Configuration.xml pause
Service
If you are running the server as a service, then you need to update the service start parameters. The easiest way is to create a vmoptions file. Create a normal text file in the same folder as your ElectroServer.exe file (usually C:\Program Files\ElectroServer_4_x_x\), and name it according to the executable that you are using. For example, if you are using ElectroServer.exe, then you need to create a file named ElectroServer.vmoptions. Each option that you wish to pass to the JVM is placed on a single line, with a line break at the end. You can pass any number of JVM options here. Using this method allows you to reconfigure the options when running as a Windows service with only a simple service restart, and will persist across restarts.
Here is an example of what a vmoptions file looks like that has three options (use the Server HotSpot JVM instead of the default client one, set the initial Java heap size to 1G, and the max Java heap size to 2G):
-server -Xms1g -Xmx2g
Unix
Adjusting the server to support more memory while running on Unix involves creating a very simple shell script.
- Stop ElectroServer if it is currently running.
- Pull up a command-prompt on your server. You can do this with telnet, SSH, or any number of other techniques depending on the server.
- Navigate to the server installation folder. For RPM installations, this defaults to /opt/ElectroServer_<version>/ otherwise it will be where ever you extracted the tar.gz file.
- Type "vi Start.sh" (without the quotes). Yes, this is the cryptic VI editor. Just follow these directions and you will be fine.
- Press "i" to enter "insert" mode.
- Enter in the following line but replace <amount> with the amount of RAM you want to allocate:
INSTALL4J_ADD_VM_PARAMS="-Xmx<amount>M"
- On the next line, enter the command you normally use to start ElectroServer.
- Press "escape".
- Type in ":wq" (as always, ignore the quotes) and press enter.
- You should be back and the command-prompt again. Run this command to allow others to execute the file:
chmod 755 Start.sh
- That's it! Now when you want to support more memory you just need to execute "./Start.sh" from this folder to start the server.
Here's a specific example of a Start.sh file that sets the amount of RAM at 1024 megabytes and runs the standalone server in a way that continues to execute even after the command window closes:
>nohup.out INSTALL4J_ADD_VM_PARAMS="-Xmx1024M" nohup ./ElectroServer &
An alternate (but more complicated) script that also works is:
>nohup.out nohup java -Xmx10G -jar lib/ElectroServer4-bootstrap.jar -mode Registry -config config/ES4Configuration.xml &
