Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/354.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.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
如何使用htmlunit解析Java堆空间_Java_Multithreading_Htmlunit_Heap Memory - Fatal编程技术网

如何使用htmlunit解析Java堆空间

如何使用htmlunit解析Java堆空间,java,multithreading,htmlunit,heap-memory,Java,Multithreading,Htmlunit,Heap Memory,我们有一个多线程应用程序,用于从各种网站抓取数据。我们使用htmlunit下载一些网站的内容。 内存不足错误的问题突然开始出现。我们的应用程序在部署服务器中使用30个线程 我们在部署中使用以下各项: htmlunit-2.12.jar htmlunit-core-js-2.12.jar Java: Java(TM) SE Runtime Environment (build 1.7.0_79-b15) 对于tomcat,我们使用以下参数: -Xms1024m -Xmx3584m -XX:+U

我们有一个多线程应用程序,用于从各种网站抓取数据。我们使用htmlunit下载一些网站的内容。 内存不足错误的问题突然开始出现。我们的应用程序在部署服务器中使用30个线程

我们在部署中使用以下各项:

htmlunit-2.12.jar
htmlunit-core-js-2.12.jar
Java: Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
对于tomcat,我们使用以下参数:

-Xms1024m -Xmx3584m 
-XX:+UseConcMarkSweepGC
-XX:PermSize=256m -XX:MaxPermSize=256m
运行于: CentOS 6.3版(4GB内存)

从与htmlunit相关的Java堆内存的各种建议中,我尝试了:

  • 从Java(TM)SE运行时环境更改为OpenJDK运行时环境
  • 已使用webClient.closeAllWindows();在任何需要的地方
  • 我没有发现这些变化带来的好运。应用程序在10分钟内使用整个堆。 我们如何克服这个内存不足错误问题

    编辑:更新到htmlunit-2.16.jar后,我们在垃圾收集方面得到了改进。(与OpenJDK一起)

    之前:(使用htmlunit-2.12.jar和Java(TM)SE运行时环境(build 1.7.0_79-b15))

    htmlunit版本是否导致问题

    编辑 在应用程序的遗留代码中,webClient在某些特定情况下没有关闭,这导致webClient对象被创建,因此堆大小增加。但是,即使关闭webclient并将其设为null,堆空间问题仍然存在


    如何解决此内存堆问题?

    爬网时如何存储数据

    您是否将其全部保存在内存模型中?或者,您正在写入磁盘/数据库吗

    如果将所有内容都保存在内存中,这可能就是问题所在


    另外,您是在处理文本/html还是在处理图像?

    在爬行时如何存储数据

    您是否将其全部保存在内存模型中?或者,您正在写入磁盘/数据库吗

    如果将所有内容都保存在内存中,这可能就是问题所在


    另外,您是只处理文本/html还是同时处理图像?

    4GB内存对于高性能web应用程序来说似乎相当低。您可以增加到8GB甚至16GB吗?我们有相同的实现,有2GB的RAM和20个线程,我们以前从未注意到这样的高CPU。查看下面的代码
    new ThreadPoolExecutor(20,40,10000,TimeUnit.SECONDS,workQueue)
    在队列达到其容量之前,您正在使用20个线程。在这之后,线程数量可以增加到40.4GB,对于高性能的web应用程序来说,RAM似乎相当低。您可以增加到8GB甚至16GB吗?我们有相同的实现,有2GB的RAM和20个线程,我们以前从未注意到这样的高CPU。查看下面的代码
    new ThreadPoolExecutor(20,40,10000,TimeUnit.SECONDS,workQueue)
    在队列达到其容量之前,您正在使用20个线程。在此之后,线程的数量可以增加到40个。我们在获取结果后立即将其写入数据库。我可以看到将任务提交到线程池的代码片段吗?您是否正在将图像加载到内存(ByteArrayInputStream)?我们在爬网时不下载任何图像。我们使用ThreadPoolExecutor来执行线程
    ThreadPoolExecutor(int corePoolSize,int maximumPoolSize,long keepAliveTime,TimeUnit,BlockingQueue workQueue)
    我可以看到将任务提交到线程池的代码片段吗?
    public class Application(){static ThreadPoolExecutor executor=new ThreadPoolExecutor(20,40,10000,TimeUnit.SECONDS,workQueue);public void method(){for(int i=0;i<20;i++){executor.execute(new FetcherThread(“FetcherThread_“+i));}}}}}}类FetcherThread扩展线程{public boolean isFetching(){return fetchStatus;}public feedbaseedferthread(字符串名称){super(fetcherThreadGroup,name);}public void run{//fetch html and update db}
    我们在获取结果后立即将其写入数据库。我可以看到将任务提交到线程池的代码片段吗?是否正在将图像加载到内存中(ByteArrayInputStream)?我们在爬网时不下载任何图像。我们使用ThreadPoolExecutor来执行线程。
    ThreadPoolExecutor(int-corePoolSize、int-maximumPoolSize、long-keepAliveTime、TimeUnit、BlockingQueue workQueue)
    我可以看到将任务提交到线程池的代码片段吗?
    公共类应用程序(){static ThreadPoolExecutor executor=new ThreadPoolExecutor(20,40,10000,TimeUnit.SECONDS,workQueue);public void method(){for(int i=0;i<20;i++){executor.execute(new FetcherThread(“FetcherThread_“+i));}}}类FetcherThread扩展线程{public boolean fetching(){return status;}public FeedBasedFetcherThread(字符串名称){super(fetcherThreadGroup,name);}public void run(){//fetch html and update db}}