gpt4 book ai didi

node.js - iisnode 性能很慢

转载 作者:搜寻专家 更新时间:2023-11-01 00:32:00 24 4
gpt4 key购买 nike

我发现 iisnode 比使用 node 命令慢。

有很多benefits使用 iisnode,但性能很差。

我正在使用来自 here 的配置文件.

知道如何加快速度吗?


更新:

我注意到每个页面调用都会重新连接一个新的 mongodb 连接。

我该如何预防?

最佳答案

此处提示在 Windows 64 位服务器上将 Node.js 与 IIS7 集成。以下提示还解决了 iisnode 的一些性能不佳问题,并演示了如何使用 Node.js Native Extensions。

总结:

Create a new Unmanaged Integrated 32-bit Application Pool dedicated for node.js. No other applications should use this pool.

这也适用于 64 位,但一些 node.js native 扩展如 Coconut2D 需要 32 位,因为 SQLite 包装。如果您不使用 native 扩展,那么您可以一直使用 64 位!

  1. 下载:iisnode-core-iis7-v0.1.19.0-x64.msi

  2. 使用此命令安装它:msiexec/i iisnode-core-iis7-v0.1.19.0-x64.msi WOW=1。这将在 64 位计算机上安装 32 位版本的 iisnode。请注意,iisnode.dll 将安装在 C:\Program Files (x86)\iisnode\iisnode.dll 中。

  3. 下载 32 位版本的 node.js(例如 node-v0.12.0-x86.msi)并将其安装到 C:\nodejs

  4. 创建一个新的应用程序池

    Name: node.jsManaged pipeline mode: Integrated 
    .NET Framework Version: No Managed CodeEnable 32-Bit Applications: TrueIdentity: administrator
  5. Assuming your Node.js Server Script file is server.js. Go the the web folder and create file node_start.cmd. In the command file you should change the current path to your wwwroot and start node.js with your server.js file. You should use double quoted paths.

    C:cd "C:\HostingSpaces\...\wwwroot""C:\nodejs\node.exe" "C:\HostingSpaces\...\wwwroot\server.js"
  6. In your server.js make sure you have process.env.PORT

    var http = require('http');http.createServer(function (req, res) {    ... your code here ...}).listen(process.env.PORT);
  7. (Optional) If you are using any node.js Native Extensions such as Coconut2D, SQLite, Cairo or WebKit modules, you must copy the *.node files and DLLs in your wwwroot\node_modules folder. Make sure you also set NTFS security to allow execution of those files or elevate the Application Pool to impersonate the Administrator. To load the native extensions use require() as shown below.

    var http = require('http');var Coconut2D = require("Coconut2D.node");http.createServer(function (req, res) {    ... your code here ...}).listen(process.env.PORT);
  8. Place the following web.config in your web root (eg. C:\HostingSpaces\...\wwwroot). This will enable IIS7 to process any non-node files such as images, static html files and xml files, and let node.js handle only its own server-side scripts.

    Having IIS handling static files and running server-side scripts on node.js side-by-side is a highly recommended practice and really boosts the performance of your web sites.

    In this example I am handling .asp files with iisnode by using a Rewrite Rule. Replace *.asp* with your node.js server script extension (eg. *.njs*). Note that there is not a root slash in the wildcard pattern; this is important as well as the last * at the end of the pattern.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="iisnode" path="node.js" verb="*" modules="iisnode" />
</handlers>
<iisnode nodeProcessCommandLine="&quot;C:\...\start_node.cmd&quot;" />
<defaultDocument>
<files>
<remove value="index.php" />
<remove value="default.aspx" />
<remove value="iisstart.htm" />
<remove value="index.html" />
<remove value="index.htm" />
<remove value="Default.htm" />
</files>
</defaultDocument>
<httpProtocol>
<customHeaders>
<remove name="X-Powered-By" />
</customHeaders>
</httpProtocol>
<rewrite>
<rules>
<rule name="CavoBoutique" patternSyntax="Wildcard">
<match url="*.asp*" />
<action type="Rewrite" url="node.js" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

关于node.js - iisnode 性能很慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28722090/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com