500 users license
$700

Friday, August 7, 2009

Tips & Tricks: Configuring ES4 Windows Command Line Options

Occasionally, when running ElectroServer 4 on a Windows platform, a developer may find that ElectroServer is running out of memory. This is usually caused by using the JavaVM memory defaults. Typically, on other platforms such as Linux, this can be solved by passing parameters to the JavaVM on the command line. When passing the same parameters to the executable files provided in the Windows installation, you will find that they aren't recognized by the executable and may result in an error. One common way to get around this is to create a batch file and place the desired command line options before the "-jar" part. For example if we needed to simply increase the maximum Java heap size to 2G, we could take a standard standalone batch file:

title "My ES4 App Without Extra Command Options"
cd server
java -jar lib\ElectroServer4-bootstrap.jar -mode StandAlone -config config\ES4Configuration.xml

pause
and add the -Xmx2g option like this:
title "My ES4 App With 2G Memory Limit"
cd server
java -Xmx2g -jar lib\ElectroServer4-bootstrap.jar -mode StandAlone -config config\ES4Configuration.xml

pause
This works for multiple command line options, however if you want to run ElectroServer as a service under Windows a batch file is not the answer. Running as a service, you can configure the command line options once within the service manager however the options do not persist when the service is restarted.

There is an elegant solution for adding command line options for ElectroServer as a service. A feature of the install4j package, which is used to create the executable files, allows for the configuration to be stored in an external file and loaded in upon execution. These files, called vmoptions files, reside in the installation path of ElectroServer (usually C:\Program Files\ElectroServer_4_x_x\) and are named using the same name as the desired executable (ex. ElectroServer.exe uses ElectroServer.vmoptions). These files are normal text files and can be created/edited with your text editor of choice. 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

That's all there is to it. Each option to be passed to the JavaVM needs to be on a single line followed by a line break. You can pass any number of JavaVM options here for your needs. The most common options are memory usage and heap-related. As an added bonus, this method will allow you to reconfigure the options when running as a Windows service with only a simple service restart and will persist across restarts.

0 Comments:

Post a Comment

<< Home