- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
注意:我浏览了有关此问题的所有主题,我知道这通常取决于 JVM 设置和高效编码,但我不知道如何进一步改进。
我正在处理 CAIDA 网络拓扑的大型文本文件 (1GB),这基本上是整个互联网 IPv4 拓扑的转储。每行的格式为“节点大陆地区国家城市纬度经度”,我需要过滤所有重复的节点(例如每个节点具有相同的纬度/经度)。
我为具有相同地理位置的所有节点分配一个唯一的名称,并维护每个地理位置的 HashMap ->已经遇到的唯一名称。我还维护每个旧名称->唯一名称的 HashMap ,因为在下一步中我必须处理另一个文件,其中这些旧名称必须映射到每个位置的新唯一名称。
我用 Java 编写了这个,因为这是我所有其他处理发生的地方,但我收到了“超出 GC 开销限制”错误。下面是我正在执行的代码和错误日志:
Scanner sc = new Scanner(new File(geo));
String line = null;
HashMap<String, String> nodeGeoMapper = new HashMap<String, String>(); // maps each coordinate to a unique node name
HashMap<String, String> nodeMapper = new HashMap<String, String>(); // maps each original node name to a filtered node name (1 name per geo coordinate)
PrintWriter output = new PrintWriter(geoFiltered);
output.println("#node.geo Name\tcontintent\tCountry\tregion\tcity\tlatitude\tlongitude");
int frenchCounter = 0;
// declare all variables used in loop to avoid creating thousands of tiny objects
String[] fields = null;
String name = null;
String continent = null;
String country = null;
String region = null;
String city = null;
double latitude = 0.0;
double longitude = 0.0;
String key = null;
boolean seenBefore = true;
String newname = null;
String nodename = null;
while (sc.hasNextLine()) {
line = sc.nextLine();
if (line.startsWith("node.geo")) {
// process a line and retrieve the fields
fields = line.split("\t"); // split all fields using the space as separator
name = fields[0];
name = name.trim().split(" ")[1]; // nodes.geo' 'N...
continent = ""; // is empty and gets skipped
country = fields[2];
region = fields[3];
city = fields[4];
latitude = Double.parseDouble(fields[5]);
longitude = Double.parseDouble(fields[6]);
// we only want one node for each coordinate pair so we map to a unique name
key = makeGeoKey(latitude, longitude);
// check if we have seen a node with these coordinates before
seenBefore = true;
if (!nodeGeoMapper.containsKey(key)) {
newname = "N"+nodeCounter;
nodeCounter++;
nodeGeoMapper.put(key, newname);
seenBefore = false;
if (country.equals("FR"))
frenchCounter++;
}
nodename = nodeGeoMapper.get(key); // retrieve the unique name assigned to these geo coordinates
nodeMapper.put(name, nodename); // keep a reference from old name to new name so we can map later
if (!seenBefore) {
// System.out.println("node.geo "+nodename+"\t"+continent+"\t"+country+"\t"+region+"\t"+city+"\t"+latitude+"\t"+longitude);
output.println("node.geo "+nodename+"\t"+continent+"\t"+country+"\t"+region+"\t"+city+"\t"+latitude+"\t"+longitude);
}
}
}
sc.close();
output.close();
nodeGeoMapper = null;
错误:
Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded
at java.util.regex.Matcher.<init>(Unknown Source)
at java.util.regex.Matcher.toMatchResult(Unknown Source)
at java.util.Scanner.match(Unknown Source)
at java.util.Scanner.hasNextLine(Unknown Source)
at DataProcessing.filterGeoNodes(DataProcessing.java:236)
at DataProcessing.main(DataProcessing.java:114)
在执行过程中,我的 java 进程一直在 80% CPU 上运行,总共有 1,000,000K(大约)内存(笔记本电脑总共有 4GB)。输出文件有 59987 个唯一节点,因此这是 GeoLocation->Name HashMap 中键值的数量。我不知道 oldName->NewName HashMap 的大小,但这应该小于 Integer.Max_value,因为我的文本文件中没有那么多行。
我的两个问题是:
如何改进代码以使用更少的内存或避免过多的 GC? (编辑:请保持 Java 7 兼容)
(已解决)我已阅读有关 JVM 设置(例如 -Xmx1024m)的线程,但我不知道 Eclipse IDE 中的何处可以更改这些设置。有人可以告诉我在哪里需要设置这些设置以及我可能想尝试哪些设置吗?
谢谢
已解决:对于有类似问题的人来说,问题在于nodeMapper hashmap,它必须存储3400万个String对象,这导致需要超过4GB的内存。我能够通过首先禁用 GC 阈值 -XX:-UseGCOverheadLimit,然后使用 -Xmx4gb 为我的 Java 进程分配 4GBRAM 来运行我的程序。处理它花了很长时间,但它确实有效,只是速度很慢,因为一旦 Java 达到 3-4GB RAM,它就会花费大量时间收集垃圾而不是处理文件。更强大的系统不会有任何问题。感谢您的帮助!
最佳答案
For the JVM arguments in Eclipse run configuration
您也可以尝试在运行时添加此选项:-XX:-使用GCOverheadLimit
Interesting explanation of this flag and your error message here
关于Java内存不足错误: GC overhead limit exceeded when processing large text file - cant figure out how to improve performance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29766248/
在我们对延迟敏感的应用程序中,我们有缓存数据(驻留在 TG 中)和在 YG 中消亡的短暂对象。我已经看到次要 GC 时间和主要 GC 时间有显着差异。我怀疑这与TG的尺寸相对较大有关。谁能解释 GC
我看到了多个建议运行 GC.Collect(GC.MaxGeneration) 的答案。 既然方法GC.Collect()会收集所有存在的分代,那么两者有什么区别吗? 也许如果只有两代而不是三代,GC
我们正在使用 UseParallelGC。 GC 日志看起来像 2016-06-09T19:38:17.362+0000:655312.397:[完整GC(人体工程学)[PSYoungGen:2291
我最近看到了两个非常好的和有教育意义的语言讲座: This first one由 Herb Sutter 撰写,介绍了 C++0x 的所有漂亮和酷炫的特性,为什么 C++ 的 future 似乎比以往
我们正在运行 gerrit 2.10.7,我们偶尔会遇到损坏的对象没有被 gerrit gc 修复的问题,即使 git gc 可以很好地修复它们。 另一方面,我读到 gerrit gc 会创建优化其他
我试图避免 Full GC(来自下面的 gc.log 示例)在生产中的 Tomcat 中运行 Grails 应用程序。关于如何更好地配置 GC 有什么建议吗? 14359.317:[完整 GC 143
我试图通过在析构函数中使用 console.WriteLine() 来确保释放某个类的实例,但输出从未出现。 我仔细搜索了任何挥之不去的引用资料以及事件订阅,但没有找到。只是为了我自己的理智,在我继续
之前看过一篇文章,说FGC影响时序,导致application出错结果。 代码示例如下: long start = System.currentTimeInMillis(); doSomething(
在 Java 中,我们可以使用 System.gc() 方法来建议 GC。今天我从this link开始了解C#中的GC.Collect()方法。 . 但我对解释有些不清楚。 第一行。 Forces
我理解 Python GC 有两种工作方式: 1) 基本引用计数 - 当“name”设置为“Tom”时,“John”下方的引用计数为零 name = "John" name = "Tom" (Refe
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
今天我们使用并发标记清除,具体如下: -XX:+UseConcMarkSweepGC 我看到一些文章推荐使用这种形式的附加参数: -XX:+UseConcMarkSweepGC -XX:+CMSInc
当我运行我的程序时,logcat 显示很多 GC Activity 喜欢 GC freed 10324 objects/ 510376 bytes in 103 ms GC freed 10324 o
2013-11-26T10:19:30.011+0800: [GC [ParNew: 2432484K->19997K(2696640K), 0.0378270 secs] 5560240K->315
在执行 GC 时,JVM 会遍历 Activity 对象,并清除未标记的对象。 根据: How to Tune Java Garbage Collection “Full GC的执行时间相对Minor
我有一个分布式缓存应用程序(内存绑定(bind),由于与集群中其他节点的交互而具有网络 I/O)在 JVM 1.7.0_51 中运行,带有 G1 垃圾收集器。这是 JVM 配置: -server -X
首先,我想让您知道,这是一个理论问题而不是实际问题,我只是好奇弱引用对象是如何被释放的。让我们快速记住 Java 中的弱引用是什么。粗略地说WeakReference意味着当没有指向“我”的强引用时,
这是运行大约 10 分钟后的输出。 Heap PSYoungGen total 7040K, used 0K [0x24060000, 0x247c0000, 0x26790000)
我正在运行一个应用程序,在 Weblogic 上使用 java 5 和 CMS 垃圾收集器。在垃圾收集日志中,我看到了消息日志,其中大部分消息我可以使用 Sun 的 Java HotSpot 虚拟机中
我有一个 ConcurrentMap> map = new ConcurrentHashMap>(); 并且希望当 SoftReference 的引用被 GC 时从映射中删除键/值对。 我该如何实现这
我是一名优秀的程序员,十分优秀!