简体   繁体   English

Java Maven Tomcat7:为jvm运行Java内存选项

[英]Java Maven Tomcat7:run java memory options for jvm

my question is right complicated for me. 我的问题对我来说很复杂。 I am running a server for a game and i have some problems setting up the java settings for memory correctly. 我正在运行用于游戏的服务器,但在正确设置内存的Java设置时遇到一些问题。

I am running Ubuntu 12.10 64bit with 32 gb ram. 我正在使用32 GB RAM运行Ubuntu 12.10 64位。

The java task should take up to 20 gb of real memory. Java任务最多需要20 gb的实际内存。 Instead of doing it it uses virtual memory all the time. 而不是这样做,它始终使用虚拟内存。

top - 19:51:44 up 15 min,  1 user,  load average: 0.29, 0.30, 0.19
Tasks: 120 total,   2 running, 118 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.9%us,  0.3%sy,  0.0%ni, 98.5%id,  0.2%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  32809368k total,  2237888k used, 30571480k free,    28092k buffers
Swap: 16776116k total,        0k used, 16776116k free,   411660k cached

PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
1876 test      20   0 46.1g 1.2g  15m S    8  3.7   1:37.17 java

currently i am running it with this command: MAVEN_OPTS="-Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000 -Xmx20480M" screen -S Test -d -m mvn -o tomcat7:run 当前,我正在使用以下命令运行它:MAVEN_OPTS =“-Xnoagent -Xrunjdwp:transport = dt_socket,server = y,suspend = n,address = 8000 -Xmx20480M”屏幕-S测试-d -m mvn -o tomcat7:run

I also tried to add it to the pom.xml (build selection): 我还尝试将其添加到pom.xml(构建选择)中:

    <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <argLine>-Xmx20480m</argLine>
                <mainClass>org.server.Server</mainClass>
                <arguments>
                </arguments>
            </configuration>
        </plugin>

Would be very nice if anyone knows a solution for this. 如果有人知道解决方案,那将非常好。

Thank you very much. 非常感谢你。

Edit: /proc/{pid}/ ls -l I cant answer to your comment directly but i dont understand where this mmap is exactly. 编辑:/ proc / {pid} / ls -l我无法直接回答您的评论,但我不知道此mmap的确切位置。 Thats what i get when i switch into the folder you wrote: 那就是我切换到您编写的文件夹后得到的结果:

    root@testserver /proc/1876 # ls -l
    total 0
    dr-xr-xr-x   2 root root 0 Nov 10 20:15 attr
    -rw-r--r--   1 root root 0 Nov 10 20:15 autogroup
    -r--------   1 root root 0 Nov 10 20:15 auxv
    -r--r--r--   1 root root 0 Nov 10 20:15 cgroup
    --w-------   1 root root 0 Nov 10 20:15 clear_refs
    -r--r--r--   1 root root 0 Nov 10 20:15 cmdline
    -rw-r--r--   1 root root 0 Nov 10 20:15 comm
    -rw-r--r--   1 root root 0 Nov 10 19:37 coredump_filter
    -r--r--r--   1 root root 0 Nov 10 20:15 cpuset
    lrwxrwxrwx   1 root root 0 Nov 10 19:39 cwd -> /srv/main
    -r--------   1 root root 0 Nov 10 20:15 environ
    lrwxrwxrwx   1 root root 0 Nov 10 19:37 exe -> /usr/lib/jvm/java-7-oracle/bin/java
    dr-x------   2 root root 0 Nov 10 19:39 fd
    dr-x------   2 root root 0 Nov 10 20:15 fdinfo
    -r--------   1 root root 0 Nov 10 20:15 io
    -r--r--r--   1 root root 0 Nov 10 20:15 latency
    -r--r--r--   1 root root 0 Nov 10 20:15 limits
    -rw-r--r--   1 root root 0 Nov 10 20:15 loginuid
    dr-x------   2 root root 0 Nov 10 20:15 map_files
    -r--r--r--   1 root root 0 Nov 10 19:37 maps
    -rw-------   1 root root 0 Nov 10 20:15 mem
    -r--r--r--   1 root root 0 Nov 10 20:15 mountinfo
    -r--r--r--   1 root root 0 Nov 10 20:15 mounts
    -r--------   1 root root 0 Nov 10 20:15 mountstats
    dr-xr-xr-x   5 root root 0 Nov 10 19:37 net
    dr-x--x--x   2 root root 0 Nov 10 20:15 ns
    -r--r--r--   1 root root 0 Nov 10 20:15 numa_maps
    -rw-r--r--   1 root root 0 Nov 10 20:15 oom_adj
    -r--r--r--   1 root root 0 Nov 10 20:15 oom_score
    -rw-r--r--   1 root root 0 Nov 10 20:15 oom_score_adj
    -r--r--r--   1 root root 0 Nov 10 20:15 pagemap
    -r--r--r--   1 root root 0 Nov 10 20:15 personality
    lrwxrwxrwx   1 root root 0 Nov 10 19:39 root -> /
    -rw-r--r--   1 root root 0 Nov 10 20:15 sched
    -r--r--r--   1 root root 0 Nov 10 20:15 schedstat
    -r--r--r--   1 root root 0 Nov 10 20:15 sessionid
    -r--r--r--   1 root root 0 Nov 10 20:15 smaps
    -r--r--r--   1 root root 0 Nov 10 20:15 stack
    -r--r--r--   1 root root 0 Nov 10 19:37 stat
    -r--r--r--   1 root root 0 Nov 10 19:37 statm
    -r--r--r--   1 root root 0 Nov 10 20:15 status
    -r--r--r--   1 root root 0 Nov 10 20:15 syscall
    dr-xr-xr-x 627 root root 0 Nov 10 20:15 task
    -r--r--r--   1 root root 0 Nov 10 20:15 wchan

Edit 2: Maps file: https://drive.google.com/file/d/0BxN3fm0mPOMUMVF1X0VEc2NSWVU/edit?usp=sharing 编辑2:地图文件: https//drive.google.com/file/d/0BxN3fm0mPOMUMVF1X0VEc2NSWVU/edit?usp = sharing

You need to work out where the extra virtual memory is coming from. 您需要确定多余的虚拟内存来自何处。 The heap is not the only memory used but the JVM or your application. 堆不是唯一使用的内存,而是JVM或您的应用程序。

I suggest you look at /proc/{pid}/maps to see if the virtual memory is coming from memory mapped files, thread stacks or native memory. 我建议您查看/proc/{pid}/maps以查看虚拟内存是否来自内存映射文件,线程堆栈或本机内存。

How many threads do you have as these can contribute a lot (if you have thousands) 您拥有多少个线程,因为它们可以贡献很大(如果您有数千个)

If you have memory mapped files, this could easily be hundreds of GB of virtual memory. 如果您有内存映射文件,则很可能就是数百GB的虚拟内存。 Given your entire system is actually using 2 GB of memory, I would suspect large memory mappings as these often use a lot of virtual memory without using read memory. 鉴于您的整个系统实际上正在使用2 GB的内存,我会怀疑大型内存映射,因为这些映射通常使用大量虚拟内存而不使用读取内存。 You should be able to see this in maps easily as it includes the path to each memory mapped file. 您应该能够轻松地在maps看到它,因为它包括每个内存映射文件的路径。

Here is a program you can use to decode the mapping. 这是一个可以用来解码映射的程序。 Run this with 与运行

java -cp . Main /proc/{pid}/maps

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new FileReader(args[0]));
        List<Mapping> mappings = new ArrayList<>();
        for (String line; (line = br.readLine()) != null; ) {
            mappings.add(new Mapping(line));
        }
        Collections.sort(mappings);
        for (Mapping mapping : mappings) {
            System.out.println(mapping);
        }
    }

    static class Mapping implements Comparable<Mapping> {
        final String details;
        final long size;

        Mapping(String details) {
            this.details = details;
            String[] words = details.split("[- ]");
            long size = 0;
            try {
                if (words.length > 2)
                size = new BigInteger(words[1], 16).longValue() - new BigInteger(words[0], 16).longValue();
            } catch (NumberFormatException e) {
                // ignored.
            }
            this.size = size;
        }

        @Override
        public int compareTo(Mapping o) {
            // reverse order.
            return -Long.compare(size, o.size);
        }

        @Override
        public String toString() {
            return String.format("%.3f %s", size / 1024.0 / 1024, details);
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM