简体   繁体   English

ArangoDB FOXX 节点扩展

[英]ArangoDB FOXX node extensions

I'm trying to move an application from sails to FOXX.我正在尝试将应用程序从风帆移动到 FOXX。 I was expecting that I could use node.js modules in FOXX but I ran into a problem.我原以为可以在 FOXX 中使用 node.js 模块,但遇到了问题。 I need to create a "working" directory on the server to perform operations to SCM repositories.我需要在服务器上创建一个“工作”目录来对 SCM 存储库执行操作。 I installed the "remove" and "mkdirp" modules.我安装了“remove”和“mkdirp”模块。 The mkdirp module calls fs.lstatSync which is reported missing under FOXX. mkdirp 模块调用 fs.lstatSync,在 FOXX 下报告丢失。 Installing a local node copy of fs doesn't solve the issues.安装 fs 的本地节点副本并不能解决问题。

If this is a problem then some of my other tasks, like spawning an external command line programs might not be possible.如果这是一个问题,那么我的一些其他任务,例如生成外部命令行程序可能无法完成。 In this case I may need to rethink moving all tasks to FOXX but that would mean replicating a lot of functionality in both sails and FOXX which could be a deployment nightmare.在这种情况下,我可能需要重新考虑将所有任务转移到 FOXX 上,但这意味着在 Sais 和 FOXX 中复制许多功能,这可能是部署噩梦。

While Foxx is very flexible, it's "just" running in ArangoDB's JavaScript environment.虽然 Foxx 非常灵活,但它“只是”在 ArangoDB 的 JavaScript 环境中运行。 This environment isn't fully compatible with Node (and hence some modules on NPM), especially when it comes to async code or file system and network I/O.此环境与 Node(以及 NPM 上的一些模块)不完全兼容,尤其是在涉及异步代码或文件系统和网络 I/O 时。

Specifically the fs module differs Node's built-in fs module.特别是fs模块不同于 Node 的内置fs模块。

Luckily the two functionality the remove and mkdirp modules provide is already built-in in ArangoDB's fs module:幸运的是, removemkdirp模块提供的两个功能已经内置在 ArangoDB 的fs模块中:

  • fs.makeDirectoryRecursive is equivalent to mkdirp fs.makeDirectoryRecursive等价于mkdirp
  • fs.removeDirectoryRecursive is equivalent to remove fs.removeDirectoryRecursive相当于remove

It is possible to spawn external processes from within ArangoDB but the relevant functionality is part of the internal API and not intended to be used in Foxx services (among other limitations there is currently no way to get at the output, just the exit status).可以从 ArangoDB 中生成外部进程,但相关功能是内部 API 的一部分,不打算在 Foxx 服务中使用(除其他限制外,目前无法获取输出,只能获取退出状态)。

Depending on what you want to achieve and what your performance requirements look like, it may indeed be a better idea to separate I/O-heavy code out into an external Node microservice.根据您想要实现的目标以及您的性能要求,将 I/O 密集型代码分离到外部 Node 微服务中确实可能是一个更好的主意。 Foxx is best-suited as an application logic wrapper around the underlying database and all Foxx code effectively runs alongside other ArangoDB JavaScript code so long-running requests can impact the ability of ArangoDB to handle other requests that need to touch the JavaScript layer. Foxx 最适合作为底层数据库的应用程序逻辑包装器,所有 Foxx 代码有效地与其他 ArangoDB JavaScript 代码一起运行,因此长时间运行的请求会影响 ArangoDB 处理需要接触 JavaScript 层的其他请求的能力。

In your particular case (you mention interacting with SCM software) I would recommend creating a small standalone Node service to deal with the SCM related logic and communicating from sails with both as necessary (or even between the two services directly).在您的特定情况下(您提到与 SCM 软件交互),我建议创建一个小型独立节点服务来处理 SCM 相关逻辑,并根据需要(甚至直接在两个服务之间)与风帆进行通信。 While this means some added overhead initially it will also be far more scalable than spending CPU cycles in ArangoDB on non-database related tasks.虽然这意味着最初会增加一些开销,但它也比在 ArangoDB 中花费 CPU 周期处理非数据库相关任务更具可扩展性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM