redis - What might cause java.lang.OutOfMemoryError here when using Protocol Buffers? -


running code below results in exception regarding java heap space.

coming .net , having handle on how gc works there wonder whether there need consider, in terms of memory management, when trying run following:

public static void main(string[] args) throws numberformatexception, parseexception, ioexception {      jedis jedis = new jedis("<hostname>");      timeseriespoints retrieved = null;      while(!finished) {          try {              finished = true;              list<string> keys = getnextfiftykeys();              string[] cachekeys = new string[keys.size()];              list<string> cacheresults = jedis.mget(keys.toarray(cachekeys));              list<timeseries> cachedtimeseries = new arraylist<timeseries>();              for(string cacheresult : cacheresults){                 try {                     retrieved = timeseriespoints.parsefrom(cacheresult.getbytes());                      timeseries timeseries = new timeseries(retrieved.getname(), retrieved.getpointslist());                      cachedtimeseries.add(timeseries);                 }                  catch (invalidprotocolbufferexception e) {                     e.printstacktrace();                 }             }              long pointscount = 0;             for(timeseries timeseries : cachedtimeseries){                 pointscount += timeseries.points.length;             }              system.out.println("retrieved: " + cachedtimeseries.size());             system.out.println("points:" + pointscount);                 } } 

an exception thrown @ timeseriespoints.parsefrom stack trace follows. not sure why exactly.

exception in thread "main" java.lang.outofmemoryerror: java heap space     @ java.util.arrays.copyof(unknown source)     @ java.util.arrays.copyof(unknown source)     @ java.util.arraylist.ensurecapacity(unknown source)     @ java.util.arraylist.add(unknown source)     @ com.wimiro.caching.timeseriesprotos$timeseriespoints.<init>(timeseriesprotos.java:115)     @ com.wimiro.caching.timeseriesprotos$timeseriespoints.<init>(timeseriesprotos.java:82)     @ com.wimiro.caching.timeseriesprotos$timeseriespoints$1.parsepartialfrom(timeseriesprotos.java:151)     @ com.wimiro.caching.timeseriesprotos$timeseriespoints$1.parsepartialfrom(timeseriesprotos.java:1)     @ com.google.protobuf.abstractparser.parsepartialfrom(abstractparser.java:141)     @ com.google.protobuf.abstractparser.parsefrom(abstractparser.java:176)     @ com.google.protobuf.abstractparser.parsefrom(abstractparser.java:188)     @ com.google.protobuf.abstractparser.parsefrom(abstractparser.java:193)     @ com.google.protobuf.abstractparser.parsefrom(abstractparser.java:49)     @ com.wimiro.caching.timeseriesprotos$timeseriespoints.parsefrom(timeseriesprotos.java:958)     @ program.main(program.java:77) 

this blows trying read 800 time series (each ~4000 data points). i'm dealing 50 time series @ time in example don't expect memory footprint grow significantly.

in .net i've no difficulty doing this. time learn me java then. need read?

you trying byte arrays java string (utf-16) got jedis (with safeencoder traduce utf-16 bytearray) calls redis (c char 8 bit encoding). think root of problem, java string incorrect , makes protobuf fail.

you should try using byte array signatures jedis:

final list<byte[]> mget = jedis.mget(bytearray1, bytearray2, ...); 

and try use protobuf on byte array. check how insert data in redis jedis, in cases recommended use byte array signatures binary data.


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -