Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Cassandra hector loader应用程序内存不足_Java_Cassandra_Hector - Fatal编程技术网

Java Cassandra hector loader应用程序内存不足

Java Cassandra hector loader应用程序内存不足,java,cassandra,hector,Java,Cassandra,Hector,这个简单的应用程序获取一个带有标题的逗号delim文件,并将其放入Cassandra。 它适用于小文件,但内存只是上升,直到内存不足异常杀死它 我错过了什么 package com.company; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; impor

这个简单的应用程序获取一个带有标题的逗号delim文件,并将其放入Cassandra。 它适用于小文件,但内存只是上升,直到内存不足异常杀死它

我错过了什么

package com.company;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import me.prettyprint.cassandra.serializers.StringSerializer;
import me.prettyprint.hector.api.Cluster;
import me.prettyprint.hector.api.Keyspace;
import me.prettyprint.hector.api.beans.HColumn;
import me.prettyprint.hector.api.factory.HFactory;
import me.prettyprint.hector.api.mutation.Mutator;

public class QuickLoad {
    public static Keyspace keyspace = null;
    public static void main(String[] args) {
        File file = new File(args[0]);
        String keyspaceName = args[1];
        String columnFamilyName = args[2];
        BufferedReader reader = null;
        try {
            keyspace = GetKeyspace(keyspaceName);
            reader = new BufferedReader(new FileReader(file));
            String fileLine = null;
            String[] headers = null;
            String[] fields = null;
            boolean headerLine = true;

            while ((fileLine = reader.readLine()) != null) {
                if (headerLine){
                    headerLine = false;
                    headers = fileLine.substring(1, fileLine.length()-1).split("\",\"");
                } else {
                    fields = fileLine.substring(1, fileLine.length()-1).split("\",\"");
                    CassandraSave(keyspace, columnFamilyName, headers, fields);
                }
            }
        }
        catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (reader != null) {
                    reader.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        System.exit(0);
    }

    public static void CassandraSave(Keyspace keyspace, String columnFamily, String[] headers, String[] columns) 
    {
        try 
        {
            Mutator mutator = HFactory.createMutator(keyspace, StringSerializer.get());
            for (int i = 1; i < headers.length-1; i++)
            {
                if ((columns[i] != null) || (!columns[i].equals("null"))) {
                    if (columns[i].length() > 0) {
                        HColumn<String, String> col = HFactory.createStringColumn(headers[i], columns[i]);
                        mutator.insert(columns[1], columnFamily, col);
                    }
                }
            }
            mutator.execute();
        } catch (Exception e){
            e.printStackTrace();
        }
    }

    public static Keyspace GetKeyspace(String keyspaceName)
    {
        String serverAddress = "localhost:9160";
        Cluster cluster = HFactory.getOrCreateCluster("My Cluster", serverAddress);
        Keyspace keyspace = HFactory.createKeyspace(keyspaceName, cluster);
        return keyspace;
    }

}
package.com公司;
导入java.io.BufferedReader;
导入java.io.File;
导入java.io.FileNotFoundException;
导入java.io.FileReader;
导入java.io.IOException;
导入me.prettyprint.cassandra.serializers.StringSerializer;
导入me.prettyprint.hector.api.Cluster;
导入me.prettyprint.hector.api.Keyspace;
导入me.prettyprint.hector.api.beans.HColumn;
导入me.prettyprint.hector.api.factory.HFactory;
导入me.prettyprint.hector.api.mutation.Mutator;
公共类快速加载{
公共静态键空间Keyspace=null;
公共静态void main(字符串[]args){
File File=新文件(args[0]);
字符串keyspaceName=args[1];
字符串columnFamilyName=args[2];
BufferedReader reader=null;
试一试{
keyspace=GetKeyspace(keyspaceName);
reader=newbufferedreader(newfilereader(file));
字符串fileLine=null;
String[]headers=null;
字符串[]字段=null;
布尔头线=真;
而((fileLine=reader.readLine())!=null){
if(车头线){
headerLine=false;
headers=fileLine.substring(1,fileLine.length()-1)。拆分(“\”,\”);
}否则{
fields=fileLine.substring(1,fileLine.length()-1)。拆分(“\”,\”);
CassandraSave(键空间、columnFamilyName、标题、字段);
}
}
}
catch(filenotfounde异常){
e、 printStackTrace();
}捕获(IOE异常){
e、 printStackTrace();
}最后{
试一试{
if(读卡器!=null){
reader.close();
}
}捕获(IOE异常){
e、 printStackTrace();
}
}
系统出口(0);
}
公共静态void CassandraSave(键空间键空间、字符串列族、字符串[]头、字符串[]列)
{
尝试
{
Mutator Mutator=HFactory.createMutator(键空间,StringSerializer.get());
对于(int i=1;i0){
HColumn col=HFactory.createStringColumn(标题[i],列[i]);
插入(列[1],列族,列);
}
}
}
mutator.execute();
}捕获(例外e){
e、 printStackTrace();
}
}
公共静态键空间GetKeyspace(字符串keyspaceName)
{
字符串serverAddress=“localhost:9160”;
Cluster Cluster=HFactory.getOrCreateCluster(“我的集群”,服务器地址);
Keyspace Keyspace=HFactory.createKeyspace(keyspaceName,cluster);
返回键空间;
}
}

如果输入文件中的一个“列”大于分配的堆,我会认为这是一个问题。你可以通过给你的变异大小s.t.设置一个上限来解决这个问题。你的CassandraSave函数在一次操作中只做100个左右的变异

加载的“com.ecyrd.speed4j.log.PeriodicalLog”的一个实例 “sun.misc.Launcher$AppClassLoader@0x899902f8”占据127293432 (99.62%)字节。关键词com.ecyrd.speed4j.log.PeriodicalLog sun.misc.Launcher$AppClassLoader@0x899902f8

看起来您使用的是旧版本的hector并遇到了问题。如果您升级到hector 0.8.0-2,则应将其修复


需要注意的一点是,speed4j在0.8.0-2中默认是禁用的,如果您想启用它,请参见。

我看到两件事-它是单线程的,批处理大小非常小

添加一个外部循环以批量收集mutator中的插入 大约500行的大小开始,看看如何进行。 下面是我用于压力测试的performant mutator insert示例:

另外,它有点老,但这里是一个解决问题的方法要点 与您描述的类似的并行加载程序:

您能将这个java参数添加到您的代码中吗-XX:+HeapDumpOnOutOfMemoryError然后用visualvm打开堆转储,告诉我们占用所有内存的是什么,Eclipse加载项MAT,因为visualvm给了我一个fitsOne实例“com.ecyrd.speed4j.log.PeriodicalLog”,该实例由“sun.misc.Launcher$AppClassLoader@0x899902f8”加载占用127293432(99.62%)字节。关键词com.ecyrd.speed4j.log.PeriodicalLog sun.misc.Launcher$AppClassLoader@0x899902F8列很小。列[]数组可能不会执行4k