Running a play framework app in Amazon EC2 micro i

2019-03-27 00:15发布

I have a really basic play! app which simply handles a couple of normal GET and POST requests and talks to a MySQL database, nothing fancy.

I ran play dist and transferred the zip file to my EC2 instance. After unzipping it, going to the bin folder and running ./myapp, I get a message:

Java HotSpot(TM) 64-Bit Server VM warning: Info: os::commit_memory ... error='Cannot allocate memory' (errorno=12)
There is insufficient memory for the Java Runtime Environment to continue.

I'm running Play version 2.2.1 and this instance has about 512MB of ram, with the 64-bit version of the Oracle JDK. Is this not enough to run a play! app or am I missing something?

Thanks.

2条回答
三岁会撩人
2楼-- · 2019-03-27 00:16

Using play 2.2.1 I had to run play dist to generate the zip file. Then I copied that to the aws instance. Once there, I extracted the zip and changed the executable file:

from:

local mem=${1:-1024}

to:

local mem=${1:-512}

That did it for me. I got the idea from here but I didn't want to just delete the logic they had there, so I just reduced the default value.

Also please note that on aws ec2 micro:

$ java -version
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.14) (amazon-65.1.11.14.57.amzn1-x86_64)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)

So you have to use the same Java JDK when runnin play dist.

EDIT:

I updated java to openjdk 7 and was able to run the sample play applications without any errors.

查看更多
放荡不羁爱自由
3楼-- · 2019-03-27 00:42

Play Framework 2.3 now has a nifty little feature.

$ /path/to/bin/<project-name> -mem 512 -J-server

Shoule get the job done.

Read http://www.playframework.com/documentation/2.3-SNAPSHOT/ProductionConfiguration


Specifying additional JVM arguments You can specify any JVM arguments to the start script. Otherwise the default JVM settings will be used:

$ /path/to/bin/ -J-Xms128M -J-Xmx512m -J-server As a convenience you can also set memory min, max, permgen and the reserved code cache size in one go; a formula is used to determine these values given the supplied parameter (which represents maximum memory):

$ /path/to/bin/ -mem 512 -J-server

查看更多
登录 后发表回答