LO 5 - conversion to pdf becomes very slow, possible because of stuck soffice.exe processes

asked 2017-09-22 11:29:35 +0200

G_from_C gravatar image

updated 2020-07-12 19:19:53 +0200

Alex Kemp gravatar image

Hello, My company is using a program that calls starts LibreOffice to convert (mostly) word documents into pdf files. These documents are delivered in zip files containing about 1000 files each. The zip is unpacked and then a program launches to convert the files. This is done by starting a java runtime which then launches LibreOffice via commandline commands. This process is given a minute of time to do its work, which is usually enough. If a timeout happens, it usually means the document has something that makes it hard to open by LO. In case of a timeout, the libreoffice process is killed. This code has been working rather well for LibreOffice 3 and 4. Because some of the files could not be correctly converted by these version of LibreOffice, we recently upgraded to LibreOffice 5. This went okay for about a month. Suddenly, we saw that the speed of the conversion was reduced to a crawl. Converting a package of files , which took between 30 minutes and an hour suddenly started taking over 6 hours. Not only that, but the libreoffice also timed. When I investigated, I noticed that the kill command would now have 2 soffice.exe processes and 2 soffice.bin processes and that a lot more times the timeout would be triggered. I also noticed that when I killed the processes manually via taskmanager, one of them would automatically return after a short while, but with a different process id as soon as even a single file was given to the convertor program. Below is the code of the process that is launched for each document that needs converting. The code for the converting :

   package be.fgov.health.converter.libreoffice;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLDecoder;

import com.sun.star.beans.PropertyValue;
import com.sun.star.comp.helper.Bootstrap;
import com.sun.star.comp.helper.BootstrapException;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.frame.XStorable;
import com.sun.star.lang.DisposedException;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.uno.Exception;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
import com.sun.star.util.XCloseable;

public class DocumentConverter
{
    public static void main(String[] args) throws IOException
    {

        int exitCode = new DocumentConverter().run(args);
        System.out.println("ProgramEnd");
        System.exit(exitCode);
    }

    private int run(String[] args) throws IOException
    {
        System.out.println("start run");
        String sourcePath = args[0];
        String targetPath = args[1];
        String fileName = extractFileName(targetPath);
        File errorFile = new File(args[2]);
        System.out.println("errorFile" + fileName);
        if (!errorFile.exists())
        {
            errorFile.createNewFile();
        }
        FileWriter fileWriter = new FileWriter(errorFile, true);
        BufferedWriter errorFileWriter = new BufferedWriter(fileWriter);
        boolean deleteOriginal = Boolean.parseBoolean(args[3]);
        String guid = args[4];
        System.out.println("guid" + guid);

        try
        {
            XComponentContext xContext = Bootstrap.bootstrap();
            XMultiComponentFactory xMultiComponentFactory ...
(more)
edit retag flag offensive close merge delete