Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.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
Javascript 使用Saxon JS识别XSLT转换的性能瓶颈_Javascript_Node.js_Xml_Xslt_Saxon - Fatal编程技术网

Javascript 使用Saxon JS识别XSLT转换的性能瓶颈

Javascript 使用Saxon JS识别XSLT转换的性能瓶颈,javascript,node.js,xml,xslt,saxon,Javascript,Node.js,Xml,Xslt,Saxon,有人能提供一些指导来找出转型中的瓶颈吗 这是Saxon js的node.js实现。我正试图提高转换一些XML文档的速度,以便能够提供一个同步API,理想情况下响应时间不超过60秒(230秒是应用程序网关的硬限制)。我还需要能够处理多达50MB大小的XML文件 我已经运行了node的内置探查器()。但是考虑到免费版本的Saxon JS的源代码不是真正的人类可读性,很难理解结果 我的代码 const path = require('path'); const SaxonJS = require('s

有人能提供一些指导来找出转型中的瓶颈吗

这是Saxon js的node.js实现。我正试图提高转换一些XML文档的速度,以便能够提供一个同步API,理想情况下响应时间不超过60秒(230秒是应用程序网关的硬限制)。我还需要能够处理多达50MB大小的XML文件

我已经运行了node的内置探查器()。但是考虑到免费版本的Saxon JS的源代码不是真正的人类可读性,很难理解结果

我的代码

const path = require('path');
const SaxonJS = require('saxon-js');
const { loadCodelistsInMem } = require('../standards_cache/codelists');
const { writeFile } = require('../config/fileSystem');
const config = require('../config/config');
const { getStartTime, getElapsedTime } = require('../config/appInsights');

// Used for easy debugging the xslt stylesheet
// Runs iati.xslt transform on the supplied XML
const runTransform = async (sourceFile) => {
    try {
        const fileName = path.basename(sourceFile);

        const codelists = await loadCodelistsInMem();

        // this pulls the right array of SaxonJS resources from the resources object
        const collectionFinder = (url) => {
            if (url.includes('codelist')) {
                // get the right filepath (remove file:// and after the ?
                const versionPath = url.split('schemata/')[1].split('?')[0];
                if (codelists[versionPath]) return codelists[versionPath];
            }
            return [];
        };

        const start = getStartTime();
        const result = await SaxonJS.transform(
            {
                sourceFileName: sourceFile,
                stylesheetFileName: `${config.TMP_BASE_DIR}/data-quality/rules/iati.sef.json`,
                destination: 'serialized',
                collectionFinder,
                logLevel: 10,
            },
            'async'
        );
        console.log(`${getElapsedTime(start)} (s)`);

        await writeFile(`performance_tests/output/${fileName}`, result.principalResult);
    } catch (e) {
        console.log(e);
    }
};

runTransform('performance_tests/test_files/test8meg.xml');
控制台输出示例:

❯ node --prof utils/runTransform.js
SEF generated by Saxon-JS 2.0 at 2021-01-27T17:10:38.029Z with -target:JS -relocate:true
79.938 (s)
❯ node --prof-process isolate-0x102d7b000-19859-v8.log > v8_log.txt
档案:

  • 示例XML:is
  • 节点分析日志
最大性能问题的V8日志片段:

 [Bottom up (heavy) profile]:
  Note: percentage shows a share of a particular caller in the total
  amount of its parent calls.
  Callers occupying less than 1.0% are not shown.

   ticks parent  name
  33729   52.5%  T __ZN2v88internal20Builtin_ConsoleClearEiPmPNS0_7IsolateE
   6901   20.5%    T __ZN2v88internal20Builtin_ConsoleClearEiPmPNS0_7IsolateE
   3500   50.7%      T __ZN2v88internal20Builtin_ConsoleClearEiPmPNS0_7IsolateE
   3197   91.3%        LazyCompile: *k /Users/nosvalds/Projects/validator-api/node_modules/saxon-js/SaxonJS2N.js:287:264
   3182   99.5%          LazyCompile: *<anonymous> /Users/nosvalds/Projects/validator-api/node_modules/saxon-js/SaxonJS2N.js:682:218
   2880   90.5%            LazyCompile: *d /Users/nosvalds/Projects/validator-api/node_modules/saxon-js/SaxonJS2N.js:734:184
[自下而上(重)配置文件]:
注意:百分比表示特定呼叫方在总数中所占的份额
其父调用的数量。
未显示占用少于1.0%的呼叫者。
勾选父项名称
33729 52.5%T_uuZN2V8820内部内置控制台隔离
6901 20.5%T\uuu Zn2V88内部20内置控制台隔离
3500 50.7%T\uuu Zn2V8820内部内置控制台隔离
3197 91.3%懒散编译:*k/Users/nosvalds/Projects/validator api/node_modules/saxon js/saxon js2n.js:287:264
3182 99.5%懒散编译:**/Users/nosvalds/Projects/validator api/node_modules/saxon js/saxon js2n.js:682:218
2880 90.5%懒散编译:*d/Users/nosvalds/Projects/validator api/node_modules/saxon js/saxon js2n.js:734:184
非常感谢。在这方面,我已经没有太多的资源可供自己使用了。我也尝试过:

  • 将stylesheetInternal参数与预解析的JSON一起使用(没有太大区别)
  • 将文档拆分为仅包含根
    根元素中的一个子元素的单独文档,分别转换每个元素,然后将其重新组合在一起,最终花费的时间是原来的2倍
最好的


尼克

你在上问了同样的问题,我在上回答了。我知道StackOverflow不喜欢只提供链接的答案,但我更喜欢通过我们自己的支持渠道而不是尽可能通过StackOverflow来支持用户。

您在上问了同样的问题,我已经在那里回答了。我知道StackOverflow不喜欢只链接的答案,但我更喜欢通过我们自己的支持渠道支持用户,而不是尽可能通过StackOverflow