Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.OutOfMemoryError: Java heap space #99

Closed
benidroe opened this issue Oct 7, 2015 · 9 comments
Closed

java.lang.OutOfMemoryError: Java heap space #99

benidroe opened this issue Oct 7, 2015 · 9 comments

Comments

@benidroe
Copy link

benidroe commented Oct 7, 2015

I use following code to write data from a BlockingQueue to InfluxDB:

    influxDB.createDatabase(dbName);
    // Flush every 2000 Points, at least every 100ms
    influxDB.setLogLevel(InfluxDB.LogLevel.NONE);

    BatchPoints batchPoints = BatchPoints
            .database(dbName)
            .tag("async", "true")
            .retentionPolicy("default")
            .consistency(InfluxDB.ConsistencyLevel.ALL)
            .build();



    try{
    Point p;
        while (true){
            // Take the next 100 Points to write
            for(int i = 0; i < 50; i++){
                p = (Point) Collector.writeQueue.take();
                batchPoints.point(p);
            }
            try{
                influxDB.write(batchPoints);
            } catch (RuntimeException r){
                System.out.println("Timeout: Writing to InfluxDB. Nothing written these time!");
            }
        }
    } catch (InterruptedException e){
        System.out.println("Can´t take element from queue " + e);
    }

After hours of running there is this exception:

    Exception in thread "Thread-0" java.lang.OutOfMemoryError: Java heap space
    at java.lang.StringCoding$StringEncoder.encode(StringCoding.java:300)
    at java.lang.StringCoding.encode(StringCoding.java:344)
    at java.lang.String.getBytes(String.java:906)
    at retrofit.mime.TypedString.convertToBytes(TypedString.java:28)
    at retrofit.mime.TypedString.<init>(TypedString.java:23)
    at org.influxdb.impl.InfluxDBImpl.write(InfluxDBImpl.java:154)
    at de.uniulm.rz.monitoring.database.DatabaseWriter.run(DatabaseWriter.java:67)
    at java.lang.Thread.run(Thread.java:745)

The root of this Issue seems to be this line:

    influxDB.write(batchPoints);

What is going wrong? Can you please help me?

@Kindrat
Copy link

Kindrat commented Oct 7, 2015

Cleanup batchpoints object after flushing to storage or create new one on every iteration

@benidroe
Copy link
Author

benidroe commented Oct 7, 2015

Thanks. How can I cleanup the batchpoints object? I fear that the garbage collector could get in trouble, if a create a new one every iteration, cause there is no destructor in java.

@Kindrat
Copy link

Kindrat commented Oct 7, 2015

You could enable batch and write single points directly, but the way batch processor works now may cause problems - e.g. data loss.

@antjori
Copy link
Contributor

antjori commented Dec 5, 2015

@benidroe why don't you simply get the points' list and clean it after each time you write?

try{
    Point p;
    while (true){
        // Take the next 50 Points to write
        for(int i = 0; i < 50; i++){
            p = (Point) Collector.writeQueue.take();
            batchPoints.point(p);
        }
        try{
            influxDB.write(batchPoints);
        } catch (RuntimeException r){
            System.out.println("Timeout: Writing to InfluxDB. Nothing written this time!");
        } finally {
            batchPoints.getPoints().clear();
        }
    }
} catch (InterruptedException e){
    System.out.println("Can´t take element from queue " + e);
}

@jiafu1115
Copy link
Contributor

jiafu1115 commented Nov 10, 2016

@majst01 @benidroe I think the issue can be closed now due to it is bug for test code: use the same instance of batchPoints. WDYT?

@majst01
Copy link
Collaborator

majst01 commented Nov 10, 2016

Yes @benidroe please let us know or close it by yourself.

@jiafu1115
Copy link
Contributor

@majst01 advice to close it directly. if @benidroe don't agree with us, he can reopen for it. Thanks

@majst01 majst01 closed this as completed Nov 10, 2016
@benidroe
Copy link
Author

Project finished since the end of last year, not verry successfully....

@jiafu1115
Copy link
Contributor

@benidroe 💯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants