1

I'm trying to convert documents(.docx/.xlsx/.pptx) to PDF using JOD Converter. I'm using OpenOffice 4.1.2 on Centos 7. My problem is, I'm getting constant CPU usage of 100% while i'm converting the file, and this is impacting the performance of overall machine. I have tried every possible option in the command line options, but ,unfortunately, haven't been able to mitigate this issue. I have searched on a lot of forums, and found that lot of other people are also facing the same problem, however, there is no solution out there. Through my readings, I realize this could be because memory leak problems in OpenOffice. Can someone please help me resolve or at-least mitigate this?

Below is the command that I use to spawn the OpenOffice instance.

/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

The code I'm using to convert the files is as follows: package 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();
        }
    }
}

And the relevant jars can be downloaded from : https://drive.google.com/file/d/0B4hS5IGxGOh9OE5Ca0RlbTdVclU/view?usp=sharing

Geek
  • 1,369
  • 1
  • 14
  • 25
  • avoid JOD Converter and print the docs with Ghostscript – deblocker Jul 14 '17 at 12:29
  • @deblocker Problem is with OpenOffice/LibreOffice and not with JOD. FYI, I have already tried Ghostscript its not helpful. It further breaks down the conversion into 2 parts Doc -> PostScript -> PDF. It increases conversion time by a good margin, which is something we really want to keep low – Geek Jul 14 '17 at 13:28
  • i did in the past a lot of pdf mass-printing, altough not with your OO version, and GS has been for me the best choice. i'm afraid, if this isn't helpful for you. good luck! – deblocker Jul 14 '17 at 16:20

2 Answers2

4

If CPU is idle, a process will take 100% CPU time by default. It's normal. If this is causing hinderance in executing other processes (highly unlikely), you can set up priorities using nice.

nice <your command>

Or, you can install cpulimit, which makes your program sleep if it reaches a predefined CPU usage. Read about it here.

Saurabh Shrivastava
  • 1,055
  • 1
  • 12
  • 26
  • I don't understand what do you mean by "If CPU is idle, a process will take 100% CPU time by default". Why would the process take 100% CPU by default. Moreover, I'm trying to find the root cause that is causing this problem and mitigate it somehow rather than limiting the CPU usage of the process. We are using a micro-service based on this and on AWS it tends to spawn a lot of VMs under load balancing. Also, sleeping the program is not a solution for us because we want the service to be up and running all the time. – Geek Jul 10 '17 at 10:51
0

By reducing the number of cores your application can use, you can prevent the system from being locked:

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

To set the affinity of CPUs using C#

Cihan Yakar
  • 2,402
  • 28
  • 30