【问题标题】:CPU Utilisation 100% while using OpenOffice4使用 OpenOffice4 时 CPU 利用率 100%
【发布时间】:2017-06-30 13:51:04
【问题描述】:

我正在尝试使用 JOD Converter 将文档 (.docx/.xlsx/.pptx) 转换为 PDF。我在 Centos 7 上使用 OpenOffice 4.1.2。我的问题是,在转换文件时,我的 CPU 使用率一直保持在 100%,这会影响整个机器的性能。我已经尝试了命令行选项中的所有可能选项,但不幸的是,无法缓解这个问题。我在很多论坛上搜索过,发现很多其他人也面临同样的问题,但是没有解决方案。通过我的阅读,我意识到这可能是因为 OpenOffice 中的内存泄漏问题。有人可以帮我解决或至少减轻这个问题吗?

下面是我用来生成 OpenOffice 实例的命令。

/opt/openoffice4/program/soffice.bin -accept=socket,host=127.0.0.1,port=8016;urp; -env:UserInstallation=file:///tmp/.jodconverter_socket_host-127.0.0.1_port-8016 -headless -nocrashreport -nodefault -nofirststartwizard -nolockcheck -nologo -norestore

我用来转换文件的代码如下: 包org.samples.docxconverters.jodconverter.pdf;

import java.io.File;

import org.apache.commons.io.FilenameUtils;
import org.artofsolving.jodconverter.OfficeDocumentConverter;
import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration;
import org.artofsolving.jodconverter.office.OfficeManager;

public class Word2PdfJod {

    public static void main(String[] args) {

        // 1) Start LibreOffice in headless mode.
        OfficeManager officeManager = null;
        try {
            officeManager = new DefaultOfficeManagerConfiguration()
                .setOfficeHome(new File("/Applications/OpenOffice.app/Contents/")).buildOfficeManager();
            officeManager.start();

            // 2) Create JODConverter converter
            OfficeDocumentConverter converter = new OfficeDocumentConverter(
                    officeManager);

            // 3) Create PDF
            createPDF(converter);

        } finally {
            // 4) Stop OpenOffice in headless mode.
            if (officeManager != null) {
                officeManager.stop();
            }
        }
    }

    private static void createPDF(OfficeDocumentConverter converter) {
        try {
            long start = System.currentTimeMillis();
            String src_file = "/Users/Aman/Documents/WindowsData/DocumentConversionPoc/Powerpoint2Pdf/JODConverterV3/Sample_pptx_files/AdeemSample2.pptx";

            System.out.println(src_file.substring(0, src_file.lastIndexOf(".")) + "_" + FilenameUtils.getExtension(src_file) );
            //Actual Conversion

            converter.convert( new File(src_file), new File( src_file.substring(0, src_file.lastIndexOf(".")) + "_" 
                        + FilenameUtils.getExtension(src_file) +"_Jod.pdf") );
            System.out.println("Time Taken in conversion -  "+ (System.currentTimeMillis() - start) + "ms");


        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
}

相关的 jars 可以从以下位置下载: https://drive.google.com/file/d/0B4hS5IGxGOh9OE5Ca0RlbTdVclU/view?usp=sharing

【问题讨论】:

  • 避免使用 JOD 转换器并使用 Ghostscript 打印文档
  • @deblocker 问题出在 OpenOffice/LibreOffice 而不是 JOD。仅供参考,我已经尝试过 Ghostscript 它没有帮助。它进一步将转换分解为两部分 Doc -> PostScript -> PDF。它大大增加了转化时间,这是我们真正希望保持的低水平
  • 我过去做了很多pdf批量打印,虽然没有使用你的OO版本,GS对我来说是最好的选择。恐怕,如果这对你没有帮助。祝你好运!

标签: memory-leaks openoffice.org jodconverter


【解决方案1】:

如果 CPU 空闲,进程默认占用 100% CPU 时间。这是正常的。如果这会阻碍其他进程的执行(极不可能),您可以使用nice 设置优先级。

nice <your command>

或者,您可以安装cpulimit,它会在您的程序达到预定义的 CPU 使用率时休眠。阅读它here

【讨论】:

  • 我不明白“如果 CPU 空闲,则默认情况下进程将占用 100% CPU 时间”是什么意思。为什么进程默认会占用 100% CPU。此外,我试图找到导致此问题的根本原因并以某种方式缓解它,而不是限制进程的 CPU 使用率。我们正在使用基于此的微服务,并且在 AWS 上,它往往会在负载平衡下产生大量虚拟机。此外,休眠程序对我们来说不是解决方案,因为我们希望服务始终处于启动状态并运行。
【解决方案2】:

通过减少您的应用程序可以使用的内核数量,您可以防止系统被锁定:

Process.GetCurrentProcess().ProcessorAffinity = (System.IntPtr)2;

To set the affinity of CPUs using C#

【讨论】:

    猜你喜欢
    • 2014-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-02
    • 2016-04-08
    • 2017-08-25
    • 1970-01-01
    相关资源
    最近更新 更多