dongyu3967 2016-01-25 13:22
浏览 81
已采纳

Inkscape服务器命令行转换速度非常慢:一个文件为12秒

I need to convert ai and eps files to svg to use with a product customization tool. To do this, I convert from ai or eps to eps (to remove any artboard or white spaces around the file) and then to svg. All this is done after upload of original file with this PHP code :

    if(!empty($_FILES))
    {
        //$rustart = getrusage();
        //var_dump($_FILES);
        $tempFile = $_FILES['file']['tmp_name'];
        $filePrefix = "file_" . time() . "_";

        $targetName = $this->santitizeFilename($_FILES['file']['name']);
        //var_dump($targetName);
        $finalName = $filePrefix . $targetName;
        $targetFile = $rootFolder . $ds . $finalName;

        move_uploaded_file($tempFile, $targetFile);

        $response['filepath'] = $relativeFolder . $ds . $this->getFilenameWithExtension($targetFile);
        //$response['success'] = file_exists($targetFile);
        $response['id_file'] = -1;

        $ext = pathinfo($targetFile, PATHINFO_EXTENSION);
        if($ext == 'svg')
        {
            $response['filepath'] = $relativeFolder . $ds . $this->replaceExtension($targetFile, 'svg');

        }
        if($ext == 'ai' || $ext == 'eps')
        {
            $epsPath = $rootFolder . $ds . $this->replaceExtension($targetFile, 'eps');
            $epsCmd = "inkscape " . $targetFile . " -D -E " . $epsPath;
            $startEps = microtime(true);
            exec($epsCmd);
            $endEps = microtime(true);

            $svgPath = $rootFolder . $ds . $this->replaceExtension($targetFile, 'svg');
            $svgCmd = "inkscape " . $epsPath . " --export-plain-svg=" . $svgPath;
            $startSvg = microtime(true);
            exec($svgCmd);
            $endSvg = microtime(true);

            $response['epsTime'] = $endEps - $startEps;
            $response['svgTime'] = $endSvg - $startSvg;

            $response['filepath'] = $relativeFolder . $ds . $this->replaceExtension($targetFile, 'svg');

            $vectorFile = new MCVectorFile();
            $vectorFile->url = $epsPath;
            if($vectorFile->save()){
                $response['id_file'] = $vectorFile->id;
            }


        }

When logging the times $epsTime and $svgTime I get about 12 seconds everytime. This is really long and I don't see it scaling well with multiple users on the site uploading files at the same time...

Also running only one command does not improve the time, it still takes about 12 seconds per command.

Is there any way I can speed this up ? Is there any other way I can make this conversion other than inkscape ?

EDIT : So I have tried running a shell script instead and it takes the same time, however, if I run the script directly on the server it takes way less time. So it seems the problem is some waiting because of missing permissions even though the files are finally created. This is the output I get when running from php :

** (inkscape:31337): WARNING **: Unable to create profile directory      (Permission denied) (13)
** Message: Cannot create profile directory /usr/share/httpd/.config/inkscape.
** Message: Inkscape will run with default settings, and new settings will not be saved. 

** (inkscape:31337): WARNING **: Could not create extension error log file     '/usr/share/httpd/.config/inkscape/extension-errors.log'

** (inkscape:31344): WARNING **: Unable to create profile directory (Permission denied) (13)
** Message: Cannot create profile directory /usr/share/httpd/.config/inkscape.
** Message: Inkscape will run with default settings, and new settings will not be saved. 

** (inkscape:31344): WARNING **: Could not create extension error log file '/usr/share/httpd/.config/inkscape/extension-errors.log'

I'm not sure I should give permissions to those folders to apache. But it seems those are configurations of inkscape that I probably don't need for what I'm doing. So is there any way I can bypass this ?

EDIT 2: So after giving the permissions on the folder I have no output from the script anymore, files are created but it still takes an insane amount of time compared to running directly on the server.

  • 写回答

1条回答 默认 最新

  • draw62188 2016-01-26 09:44
    关注

    So it turns out the problem was the number of fonts installed. It seems inkscape loads all the fonts at start and since I had the whole google fonts installed it took forever.

    So I removed all the google fonts by deleting them and ran fc-cache to update.

    I also updated from 0.48 to 0.91 which seems got a good performance boost too. When I still had fonts installed the script took 80 seconds on first run but on second run only 13 seconds where with 0.48 I was consistently around 22/24 seconds.

    Now the script runs in less than a second, thank god!

    Another improvement now would be to run both commands with Inkscape's shell mode to avoid it being loaded twice.

    Also the permissions problem was caused by SELinux and solved by a chcon on the .config folder in the home dir of the apache user

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序