Solr Dataimporthandler 导入MySQL 内存溢出。

  最近准备把一千九百多万数据导入Solr中,在以前测试数据只有一两百万,全量导入没有任务问题。但是,换成一千九百万数据时,solr报内存异常(java.lang.OutOfMemoryError:GC overhead limit exceeded),整个tomcat无法使用。我发现,我给tomcat最大堆内存512M。我觉得,可能是内存过小,于是,我把内存改大些,1024M(set JAVA_OPTS=-server -Xms1024m -Xmx1024m -XX:PermSize=128M -XX:MaxPermSize=256M )。结果,还是内存溢出。我想已经不是tomcat内存的问题(当然,如果你的内存足够大,也是可行的)。问题,应该出在solr的dataimporthandler取数据那块。solr除了内存溢出错误,还有其他异常:

  

Full Import failed:java.lang.RuntimeException: java.lang.RuntimeException: org.apache.solr.handler.dataimport.DataImportHandlerException: Unable to execute query: select * from POI Processing Document # 1
	at org.apache.solr.handler.dataimport.DocBuilder.execute(DocBuilder.java:278)
	at org.apache.solr.handler.dataimport.DataImporter.doFullImport(DataImporter.java:411)
	at org.apache.solr.handler.dataimport.DataImporter.runCmd(DataImporter.java:483)
	at org.apache.solr.handler.dataimport.DataImporter$1.run(DataImporter.java:464)
Caused by: java.lang.RuntimeException: org.apache.solr.handler.dataimport.DataImportHandlerException: Unable to execute query: select * from POI Processing Document # 1
	at org.apache.solr.handler.dataimport.DocBuilder.buildDocument(DocBuilder.java:418)
	at org.apache.solr.handler.dataimport.DocBuilder.doFullDump(DocBuilder.java:331)
	at org.apache.solr.handler.dataimport.DocBuilder.execute(DocBuilder.java:239)
	... 3 more
Caused by: org.apache.solr.handler.dataimport.DataImportHandlerException: Unable to execute query: select * from POI Processing Document # 1
	at org.apache.solr.handler.dataimport.DataImportHandlerException.wrapAndThrow(DataImportHandlerException.java:71)
	at org.apache.solr.handler.dataimport.JdbcDataSource$ResultSetIterator.<init>(JdbcDataSource.java:281)
	at org.apache.solr.handler.dataimport.JdbcDataSource.getData(JdbcDataSource.java:238)
	at org.apache.solr.handler.dataimport.JdbcDataSource.getData(JdbcDataSource.java:42)
	at org.apache.solr.handler.dataimport.SqlEntityProcessor.initQuery(SqlEntityProcessor.java:59)
	at org.apache.solr.handler.dataimport.SqlEntityProcessor.nextRow(SqlEntityProcessor.java:73)
	at org.apache.solr.handler.dataimport.EntityProcessorWrapper.nextRow(EntityProcessorWrapper.java:243)
	at org.apache.solr.handler.dataimport.DocBuilder.buildDocument(DocBuilder.java:477)
	at org.apache.solr.handler.dataimport.DocBuilder.buildDocument(DocBuilder.java:416)
	... 5 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 395,021 milliseconds ago.  The last packet sent successfully to the server was 395,021 milliseconds ago.
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
	at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
	at com.mysql.jdbc.MysqlIO.nextRowFast(MysqlIO.java:1653)
	at com.mysql.jdbc.MysqlIO.nextRow(MysqlIO.java:1409)
	at com.mysql.jdbc.MysqlIO.readSingleRowSet(MysqlIO.java:2883)
	at com.mysql.jdbc.MysqlIO.getResultSet(MysqlIO.java:476)
	at com.mysql.jdbc.MysqlIO.readResultsForQueryOrUpdate(MysqlIO.java:2576)
	at com.mysql.jdbc.MysqlIO.readAllResults(MysqlIO.java:1757)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2167)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2637)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2566)
	at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:782)
	at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:625)
	at org.apache.solr.handler.dataimport.JdbcDataSource$ResultSetIterator.<init>(JdbcDataSource.java:274)
	... 12 more
Caused by: java.io.EOFException: Can not read response from server. Expected to read 39 bytes, read 30 bytes before connection was unexpectedly lost.
	at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2497)
	at com.mysql.jdbc.MysqlIO.nextRowFast(MysqlIO.java:1634)
	... 23 more

  我搜索了一下Solr的wiki,了解到solr jdbc取数据时,setBatchSize的问题。默认,会把很多数据放到内存中,这也是导致我的内存居高不下,后来导致内存溢出的原因。于是,我修改dataimporthandler配置文件:batchSize="-1" 解决内存溢出  

  配置文件修改如下:

      <dataSource driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/world" user="root" password="root" batchSize="-1" />

  重启一个solr的core,重新导入,问题解决。

  

  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值