gpt4 book ai didi

node.js - Webpack占用9GB内存正常吗?

转载 作者:IT老高 更新时间:2023-10-28 23:01:53 27 4
gpt4 key购买 nike

根据 Ubuntu 上的任务管理器,node 有 8 个进程正在运行,占用 900mb 到 1.3gb 的内存。

感觉太过分了。幸好我的电脑有 12GB 内存,但这是否太多了?如果有,知道为什么这么多吗?

当 webpack 检测到更改并开始运行时,我的计算机确实经常死机并且有时会打嗝。

webpack:^3.6.0,bundle tracker:^0.2.0,dashboard:1.0.0-5,webpack-dev-server:^2.2.0,babel:^6.3.26

我正在使用 WebpackDevServer,例如:

new WebpackDevServer(webpack(config), {
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'Content-Type, Authorization, x-id, Content-Length, X-Requested-With',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS'
},

historyApiFallback: true,
hot: true,
publicPath: config.output.publicPath,
quiet: true, // Shows WebpackDashboard instead.
watchOptions: {
aggregateTimeout: 300,
poll: 1000
}
}).listen( ... );

这是我的 webpack 文件:

const config = {
context: __dirname,

devtool: 'eval-cheap-module-source-map',

module: {
loaders: [
{
test: /\.js[x]?$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
{
test: /\.s[ac]ss$/,
exclude: '/node_modules/',
use: [{
loader: 'style-loader',
options: {
sourceMap: true
}
}, {
loader: 'css-loader',
options: {
sourceMap: true
}
}, {
loader: 'sass-loader',
options: {
sourceMap: true,
includePaths: [path.resolve(__dirname)]
}
}]
},
{
test: /\.(ttf|otf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
exclude: '/node_modules/',
loader: 'file-loader'
},
{
test: /\.(jpe?g|png|gif)$/,
exclude: '/node_modules/',

// If an image is less than 10kb, use data-url for images, otherwise
// falls back to file-loader.
loaders: ['url-loader?limit=10000&name=images/[hash:12].[ext]']
}
]
},

resolve: {
descriptionFiles: ['package.json'],
extensions: ['.js', '.jsx', '.scss'],
mainFiles: ['index'],
modules: ['node_modules', path.resolve(__dirname)],
}
};

config.entry = {
main: [
'react-hot-loader/patch',
'babel-polyfill',
'./index.jsx',
'webpack/hot/only-dev-server',
`webpack-dev-server/client?http://${ localConfig.ip }:${ localConfig.port }`
]
};


config.output = {
path: path.resolve('./dist/'),
publicPath: `http://${ localConfig.ip }:${ localConfig.port }/assets/bundles/`,
filename: '[name].js'
};


config.plugins = [
new webpack.HotModuleReplacementPlugin(),

new webpack.NoEmitOnErrorsPlugin(),

// Used by Django.
new BundleTracker({ filename: './webpack-stats-dev.json' }),

new webpack.NamedModulesPlugin(),

new DashboardPlugin(dashboard.setData)
];

如果有人知道一个很好的故障排除步骤列表,那将非常有帮助。

最佳答案

看起来您的进程需要 1GB,但由于它们被执行 8 次,作为单独的进程......那么它们需要 8GB 的​​内存。这就是线程获胜的地方。

如果测试有问题,您可以强制 GC。就我而言,构建速度非常快。获取依赖项需要时间,而且测试执行成本很高。如果您的情况也是如此,请查看 here为:

If I call gc() manually every 100 requests, RSS does not go above 70 MiB.

正如你所写,难题。我认为你处于边缘。

关于node.js - Webpack占用9GB内存正常吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46676243/

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