hbase 大数据存储 内存溢出。

五个线程,每五分钟put50000数据。如果hbase服务停止,线程还在调用hbase 客户端存储方法,Htable 一直put数据到内存中,导致内存溢出。

colincheng - 大数据工程师@易宝支付

赞同来自: 编程小梦 mhf0510

以前用Hbase的时候,没发现服务停止后,客户端还能继续PUT数据直到内存溢出,这种做法是非常不安全的,我觉得服务端停止后,因为有缓存的关系,有可能会有一定延迟,但是缓存的数据与hbase服务数据同步的时候,就会得知Hbase服务已经停止,而不会出现你所说的一直put到服务器内存溢出为止。建议把报错信息也发出来,我们分析一下。

mopishv0 - 高级开发工程师@美团

赞同来自: fish mhf0510

1 map遍历推荐用 for (Map.Entry e : dataMap.entrySet()),这样效率更高。 2 htable的put是有缓冲的,缓冲写满会自动flush,flush是阻塞的过程,所以内存使用过多主要是由于hTable.setWriteBufferSize(2 * 5000000); 这里声明了10MB的buffer,5个线程就是50MB,但是这个函数和外围线程的关系并没有体现出来。 3 下次问这类问题,最好能带上异常栈。

mhf0510

赞同来自:

各位这是代码,希望那位高手帮忙提供一个解决思路public boolean insertDataList(String tableName, List<HBaseEntity> dataList) {         boolean flag = false;         HTable hTable = null;         if (ParamValidator.validatorParamsIsEmpty(tableName)) {             LOGGER.info("tableName is null");             return false;         }         try {             Configuration config = getConfiguration();             if (null != config) {                 hTable = new HTable(config, tableName);                 LOGGER.info("hTable init over");                 if (null != hTable) {                     hTable.setAutoFlush(false, false);                     hTable.setWriteBufferSize(2 * 5000000);                     if (null != dataList && dataList.size() > 0) {                         for (HBaseEntity hbaseEntity : dataList) {                             Put put = new Put(                                     Bytes.toBytes(hbaseEntity.getRowKey()));                             // 获取插入的数据                             Map<String, Map<String, String>> dataMap = hbaseEntity                                     .getDataMap();                             Set<String> columnFamilyKey = dataMap.keySet();                             // 遍历所有columnfamily                             for (Iterator it = columnFamilyKey.iterator(); it                                     .hasNext();) {// 遍历列簇                                 String columnFamily = (String) it.next();                                 Map<String, String> columnMap = dataMap                                         .get(columnFamily);                                 Set<String> columnKey = columnMap.keySet();                                 for (Iterator cit = columnKey.iterator(); cit                                         .hasNext();) {// 遍历列值                                     String column = (String) cit.next();                                     String value = columnMap.get(column);                                     put.add(columnFamily.getBytes(),                                             column.getBytes(), value.getBytes());// 手动设置时间戳                                 }                             }                              hTable.put(put);                           }                     }                     flag = true;                 } else {                     LOGGER.info("hbase table is null");                 }             }                                   } catch (Exception e) {             LOGGER.info("insert data error:" + e.getMessage());              flag = false;         } finally {             if (null != hTable) {                 try {                     hTable.close();                 } catch (IOException e) {                     LOGGER.info("close table error" + e.getMessage());                     LOGGER.logException(e);                 }             }         }         LOGGER.info("insertDataList over");         return flag;     }

编程小梦 - 大数据

赞同来自:

代码没有细看,不过根据你的描述。如果hbase服务停止,你的客户端应该是可以获得信息,并及时停止导入的。 内存是有限的,你持续向内存写入,内存必然会溢出。  

fish - Hadooper

赞同来自:

确定是内存溢出么?抛了什么异常?

mhf0510

赞同来自:

由于htable对象一直存在,关闭不掉。所以必然会内存溢出。如果Hbase服务端停止,怎么关闭Htable

mhf0510

赞同来自:

webservice接口提供保存与查询方法。flush检查到hbase服务端停止不能保存数据。flush不掉数据,线程到堵塞状态,线程一直在执行。hbase服务停止,htable对象还一直存在,什么办法能让在hbase服务端停止以后,我应该做的措施是什么?这是我的异常信息。在关闭hbase服务端的情况下。
cRequestor.invoke(SpecificRequestor.java:88)
	at com.sun.proxy.$Proxy93.queryMultiTimeSeries(Unknown Source)
	at com.cloudera.cmf.protocol.firehose.nozzle.TimeoutNozzleIPC.queryMultiTimeSeries(TimeoutNozzleIPC.java:356)
	at com.cloudera.server.cmf.tsquery.TimeSeriesMultiRequest.call(TimeSeriesMultiRequest.java:82)
	at com.cloudera.server.cmf.tsquery.TimeSeriesMultiRequest.call(TimeSeriesMultiRequest.java:18)
	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.ConnectException: Connection refused
	at java.net.PlainSocketImpl.socketConnect(Native Method)
	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
	at java.net.Socket.connect(Socket.java:579)
	at sun.net.NetworkClient.doConnect(NetworkClient.java:175)
	at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)
	at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)
	at sun.net.www.http.HttpClient.<init>(HttpClient.java:211)
	at sun.net.www.http.HttpClient.New(HttpClient.java:308)
	at sun.net.www.http.HttpClient.New(HttpClient.java:326)
	at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:996)
	at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:932)
	at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:850)
	at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1091)
	at org.apache.avro.ipc.HttpTransceiver.writeBuffers(HttpTransceiver.java:71)
	at org.apache.avro.ipc.Transceiver.transceive(Transceiver.java:58)
	at org.apache.avro.ipc.Transceiver.transceive(Transceiver.java:72)
	at org.apache.avro.ipc.Requestor.request(Requestor.java:147)
	at org.apache.avro.ipc.Requestor.request(Requestor.java:101)
	at org.apache.avro.ipc.specific.SpecificRequestor.invoke(SpecificRequestor.java:72)
	... 8 more
2015-10-18 12:43:16,925 WARN 7088581@scm-web-1929:com.cloudera.server.cmf.tsquery.TimeSeriesQueryService: com.cloudera.server.cmf.tsquery.TimeSeriesQueryService@175139b failed on nozzle HOST_MONITORING
java.util.concurrent.ExecutionException: org.apache.avro.AvroRemoteException: java.net.ConnectException: Connection refused
	at java.util.concurrent.FutureTask.report(FutureTask.java:122)
	at java.util.concurrent.FutureTask.get(FutureTask.java:202)
	at com.cloudera.server.cmf.tsquery.NozzleRequest.getResponse(NozzleRequest.java:70)
	at com.cloudera.server.cmf.tsquery.TimeSeriesQueryService.queryTimeSeries(TimeSeriesQueryService.java:344)
	at com.cloudera.server.web.cmf.charts.TimeSeriesQueryController.queryTimeSeriesHelper(TimeSeriesQueryController.java:303)
	at com.cloudera.server.web.cmf.charts.TimeSeriesQueryController.queryTimeSeries(TimeSeriesQueryController.java:269)
	at sun.reflect.GeneratedMethodAccessor836.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
	at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:436)
	at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:424)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:669)
	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:585)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:595)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
	at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1221)
	at org.mortbay.servlet.UserAgentFilter.doFilter(UserAgentFilter.java:78)
	at org.mortbay.servlet.GzipFilter.doFilter(GzipFilter.java:131)
	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
	at com.jamonapi.http.JAMonServletFilter.doFilter(JAMonServletFilter.java:48)
	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
	at com.cloudera.enterprise.JavaMelodyFacade$MonitoringFilter.doFilter(JavaMelodyFacade.java:109)
	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:311)
	at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:116)
	at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
	at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
	at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:101)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
	at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
	at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:146)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
	at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
	at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
	at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:182)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
	at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
	at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
	at org.springframework.security.web.session.ConcurrentSessionFilter.doFilter(ConcurrentSessionFilter.java:125)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
	at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:173)
	at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
	at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:399)
	at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
	at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
	at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
	at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:767)
	at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:450)
	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
	at org.mortbay.jetty.handler.StatisticsHandler.handle(StatisticsHandler.java:53)
	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
	at org.mortbay.jetty.Server.handle(Server.java:326)
	at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
	at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:945)
	at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756)
	at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
	at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
	at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)
	at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Caused by: org.apache.avro.AvroRemoteException: java.net.ConnectException: Connection refused
	at org.apache.avro.ipc.specific.SpecificRequestor.invoke(SpecificRequestor.java:88)
	at com.sun.proxy.$Proxy93.queryMultiTimeSeries(Unknown Source)
	at com.cloudera.cmf.protocol.firehose.nozzle.TimeoutNozzleIPC.queryMultiTimeSeries(TimeoutNozzleIPC.java:356)
	at com.cloudera.server.cmf.tsquery.TimeSeriesMultiRequest.call(TimeSeriesMultiRequest.java:82)
	at com.cloudera.server.cmf.tsquery.TimeSeriesMultiRequest.call(TimeSeriesMultiRequest.java:18)
	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.ConnectException: Connection refused
	at java.net.PlainSocketImpl.socketConnect(Native Method)
	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
	at java.net.Socket.connect(Socket.java:579)
	at sun.net.NetworkClient.doConnect(NetworkClient.java:175)
	at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)
	at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)
	at sun.net.www.http.HttpClient.<init>(HttpClient.java:211)
	at sun.net.www.http.HttpClient.New(HttpClient.java:308)
	at sun.net.www.http.HttpClient.New(HttpClient.java:326)
	at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:996)
	at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:932)
	at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:850)
	at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1091)
	at org.apache.avro.ipc.HttpTransceiver.writeBuffers(HttpTransceiver.java:71)
	at org.apache.avro.ipc.Transceiver.transceive(Transceiver.java:58)
	at org.apache.avro.ipc.Transceiver.transceive(Transceiver.java:72)
	at org.apache.avro.ipc.Requestor.request(Requestor.java:147)
	at org.apache.avro.ipc.Requestor.request(Requestor.java:101)
	at org.apache.avro.ipc.specific.SpecificRequestor.invoke(SpecificRequestor.java:72)
	... 8 more

要回复问题请先登录注册