我尝试在免费的AWS EC 2示例上运行节点服务器。在本地,我可以构建和运行我的服务器,但在AWS上它一直崩溃。
我运行$ npm run build
错误信息:
findus | <--- Last few GCs --->
findus |
findus | [18:0x55b075815d80] 19411 ms: Mark-sweep 487.8 (491.0) -> 487.2 (491.2) MB, 721.0 / 0.0 ms (average mu = 0.110, current mu = 0.019) allocation failure scavenge might not succeed
findus | [18:0x55b075815d80] 20137 ms: Mark-sweep 487.9 (491.2) -> 487.3 (491.5) MB, 723.5 / 0.0 ms (average mu = 0.060, current mu = 0.004) allocation failure scavenge might not succeed
findus |
findus |
findus | <--- JS stacktrace --->
findus |
findus | ==== JS stack trace =========================================
findus |
findus | 0: ExitFrame [pc: 0x55b070dd2eb9]
findus | Security context: 0x24cb05dc0921 <JSObject>
findus | 1: setParentPointers(aka setParentPointers) [0x34cec2b85941] [/app/node_modules/typescript/lib/tsc.js:~27701] [pc=0x770d079eae0](this=0x0bad1a5804b9 <undefined>,0x3d868a943641 <Node map = 0x1c6b95afc031>,0x3d868a944181 <Node map = 0x1c6b95af7a81>)
findus | 2: /* anonymous */(aka /* anonymous */) [0x33ec79ae66b1] [/app/node_modules/typescript/lib/tsc.js:27703]...
findus |
findus | FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
findus |
findus | Writing Node.js report to file: report.20200502.192713.18.0.001.json
findus | Node.js report completed
findus | Aborted (core dumped)
findus | npm ERR! code ELIFECYCLE
findus | npm ERR! errno 134
findus | npm ERR! findus-backend@1.0.0 prod: `tsc && node build/index.js`
findus | npm ERR! Exit status 134
findus | npm ERR!
findus | npm ERR! Failed at the findus-backend@1.0.0 prod script.
findus | npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
findus |
findus | npm ERR! A complete log of this run can be found in:
findus | npm ERR! /root/.npm/_logs/2020-05-02T19_27_18_024Z-debug.log
findus exited with code 134
有没有办法在内存不足的服务器上运行tsc
?
我的package.json
{
"name": "findus-backend",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "tsc",
"dev": "nodemon source/index.ts",
"prod": "tsc && node build/index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"@types/cron": "^1.7.1",
"@types/express": "^4.17.2",
"@types/lodash": "^4.14.149",
"@types/mongodb": "^3.3.13",
"@types/mongoose": "^5.5.34",
"@types/node": "^12.12.25",
"@types/xml2js": "^0.4.5",
"cron": "^1.8.2",
"express": "^4.17.1",
"googleapis": "^47.0.0",
"lodash": "^4.17.15",
"mongoose": "^5.8.1",
"rss-parser": "^3.7.3"
},
"devDependencies": {
"nodemon": "^2.0.2",
"ts-node": "^8.6.2",
"typescript": " 3.3.3"
}
}
报告:
{
"header": {
"reportVersion": 2,
"event": "Allocation failed - JavaScript heap out of memory",
"trigger": "FatalError",
"filename": "report.20200502.194450.30170.0.001.json",
"dumpEventTime": "2020-05-02T19:44:50Z",
"dumpEventTimeStamp": "1588448690491",
"processId": 30170,
"threadId": null,
"cwd": "/home/ubuntu/Findus/Backend",
"commandLine": [
"node",
"/home/ubuntu/Findus/Backend/node_modules/.bin/tsc"
],
"nodejsVersion": "v12.16.3",
"glibcVersionRuntime": "2.27",
"glibcVersionCompiler": "2.17",
"wordSize": 64,
"arch": "x64",
"platform": "linux",
"componentVersions": {
"node": "12.16.3",
"v8": "7.8.279.23-node.35",
"uv": "1.34.2",
"zlib": "1.2.11",
"brotli": "1.0.7",
"ares": "1.16.0",
"modules": "72",
"nghttp2": "1.40.0",
"napi": "5",
"llhttp": "2.0.4",
"http_parser": "2.9.3",
"openssl": "1.1.1g",
"cldr": "36.0",
"icu": "65.1",
"tz": "2019c",
"unicode": "12.1"
},
"release": {
"name": "node",
"lts": "Erbium",
"headersUrl": "https://nodejs.org/download/release/v12.16.3/node-v12.16.3-headers.tar.gz",
"sourceUrl": "https://nodejs.org/download/release/v12.16.3/node-v12.16.3.tar.gz"
},
"osName": "Linux",
"osRelease": "5.3.0-1017-aws",
"osVersion": "#18~18.04.1-Ubuntu SMP Wed Apr 8 15:12:16 UTC 2020",
"osMachine": "x86_64",
"cpus": [
{
"model": "Intel(R) Xeon(R) CPU E5-2676 v3 @ 2.40GHz",
"speed": 2400,
"user": 7780600,
"nice": 141600,
"sys": 5849500,
"idle": 1138420300,
"irq": 0
}
],
"networkInterfaces": [
{
"name": "lo",
"internal": true,
"mac": "00:00:00:00:00:00",
"address": "127.0.0.1",
"netmask": "255.0.0.0",
"family": "IPv4"
},
{
"name": "eth0",
"internal": false,
"mac": "0a:85:22:ae:d6:7a",
"address": "172.31.45.156",
"netmask": "255.255.240.0",
"family": "IPv4"
},
{
"name": "lo",
"internal": true,
"mac": "00:00:00:00:00:00",
"address": "::1",
"netmask": "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff",
"family": "IPv6",
"scopeid": 0
},
{
"name": "eth0",
"internal": false,
"mac": "0a:85:22:ae:d6:7a",
"address": "fe80::885:22ff:feae:d67a",
"netmask": "ffff:ffff:ffff:ffff::",
"family": "IPv6",
"scopeid": 2
}
],
"host": "ip-172-31-45-156"
},
"javascriptStack": {
"message": "No stack.",
"stack": [
"Unavailable."
]
},
"nativeStack": [
{
"pc": "0x0000000000b46955",
"symbol": "report::TriggerNodeReport(v8::Isolate*, node::Environment*, char const*, char const*, std::string const&, v8::Local<v8::String>) [node]"
},
{
"pc": "0x0000000000a09c8f",
"symbol": "node::OnFatalError(char const*, char const*) [node]"
},
{
"pc": "0x0000000000b7d71e",
"symbol": "v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]"
},
{
"pc": "0x0000000000b7da99",
"symbol": "v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]"
},
{
"pc": "0x0000000000d2a1f5",
"symbol": " [node]"
},
{
"pc": "0x0000000000d2a886",
"symbol": "v8::internal::Heap::RecomputeLimits(v8::internal::GarbageCollector) [node]"
},
{
"pc": "0x0000000000d37105",
"symbol": "v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [node]"
},
{
"pc": "0x0000000000d37fb5",
"symbol": "v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]"
},
{
"pc": "0x0000000000d3aa6c",
"symbol": "v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]"
},
{
"pc": "0x0000000000d0163b",
"symbol": "v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [node]"
},
{
"pc": "0x000000000104300e",
"symbol": "v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [node]"
},
{
"pc": "0x00000000013c5b79",
"symbol": " [node]"
}
],
"javascriptHeap": {
"totalMemory": 515842048,
"totalCommittedMemory": 514610432,
"usedMemory": 510824048,
"availableMemory": 11324416,
"memoryLimit": 525336576,
"heapSpaces": {
"read_only_space": {
"memorySize": 262144,
"committedMemory": 33088,
"capacity": 32808,
"used": 32808,
"available": 0
},
"new_space": {
"memorySize": 2097152,
"committedMemory": 1357744,
"capacity": 1047456,
"used": 340552,
"available": 706904
},
"old_space": {
"memorySize": 469377024,
"committedMemory": 469280296,
"capacity": 467181736,
"used": 467106208,
"available": 75528
},
"code_space": {
"memorySize": 1216512,
"committedMemory": 1059392,
"capacity": 925664,
"used": 925664,
"available": 0
},
"map_space": {
"memorySize": 528384,
"committedMemory": 519080,
"capacity": 326640,
"used": 326640,
"available": 0
},
"large_object_space": {
"memorySize": 42311680,
"committedMemory": 42311680,
"capacity": 42089392,
"used": 42089392,
"available": 0
},
"code_large_object_space": {
"memorySize": 49152,
"committedMemory": 49152,
"capacity": 2784,
"used": 2784,
"available": 0
},
"new_large_object_space": {
"memorySize": 0,
"committedMemory": 0,
"capacity": 1047456,
"used": 0,
"available": 1047456
}
}
},
"resourceUsage": {
"userCpuSeconds": 19.9575,
"kernelCpuSeconds": 0.539212,
"cpuConsumptionPercent": 97.6036,
"maxRss": 580542464,
"pageFaults": {
"IORequired": 1,
"IONotRequired": 149827
},
"fsActivity": {
"reads": 92264,
"writes": 0
}
},
"uvthreadResourceUsage": {
"userCpuSeconds": 9.14098,
"kernelCpuSeconds": 0.234258,
"cpuConsumptionPercent": 44.644,
"fsActivity": {
"reads": 92008,
"writes": 0
}
},
"libuv": [
],
"workers": [
],
"environmentVariables": {
"LESSOPEN": "| /usr/bin/lesspipe %s",
"npm_package_devDependencies_ts_node": "^8.6.2",
"npm_config_cache_lock_stale": "60000",
"npm_config_ham_it_up": "",
"npm_config_legacy_bundling": "",
"npm_config_sign_git_tag": "",
"MAIL": "/var/mail/ubuntu",
"USER": "ubuntu",
"SSH_CLIENT": "5.231.149.16 39054 22",
"LC_TIME": "C.UTF-8",
"npm_config_user_agent": "npm/6.14.4 node/v12.16.3 linux x64",
"npm_config_always_auth": "",
"npm_config_bin_links": "true",
"npm_config_key": "",
"npm_package_dependencies__types_lodash": "^4.14.149",
"npm_package_devDependencies_nodemon": "^2.0.2",
"npm_config_allow_same_version": "",
"npm_config_description": "true",
"npm_config_fetch_retries": "2",
"npm_config_heading": "npm",
"npm_config_if_present": "",
"npm_config_init_version": "1.0.0",
"npm_config_user": "",
"npm_node_execpath": "/usr/bin/node",
"SHLVL": "1",
"npm_config_prefer_online": "",
"npm_config_noproxy": "",
"HOME": "/home/ubuntu",
"OLDPWD": "/home/ubuntu/Findus",
"npm_package_dependencies__types_mongoose": "^5.5.34",
"npm_config_force": "",
"SSH_TTY": "/dev/pts/0",
"npm_config_only": "",
"npm_config_read_only": "",
"npm_config_cache_min": "10",
"npm_config_init_license": "ISC",
"npm_config_editor": "vi",
"npm_config_rollback": "true",
"npm_config_tag_version_prefix": "v",
"LC_MONETARY": "C.UTF-8",
"npm_config_cache_max": "Infinity",
"npm_config_timing": "",
"npm_config_userconfig": "/home/ubuntu/.npmrc",
"npm_config_engine_strict": "",
"npm_config_init_author_name": "",
"npm_config_init_author_url": "",
"npm_config_preid": "",
"npm_config_tmp": "/tmp",
"npm_package_description": "",
"npm_package_devDependencies_typescript": "^3.7.5",
"npm_config_depth": "Infinity",
"npm_config_package_lock_only": "",
"npm_config_save_dev": "",
"npm_config_usage": "",
"npm_config_metrics_registry": "https://registry.npmjs.org/",
"npm_config_cafile": "",
"npm_config_otp": "",
"npm_config_package_lock": "true",
"npm_config_progress": "true",
"npm_config_https_proxy": "",
"npm_config_save_prod": "",
"npm_package_scripts_dev": "nodemon source/index.ts",
"npm_config_audit": "true",
"npm_config_cidr": "",
"npm_config_onload_script": "",
"npm_config_sso_type": "oauth",
"LOGNAME": "ubuntu",
"npm_package_scripts_prod": "tsc && node build/index.js",
"npm_config_rebuild_bundle": "true",
"npm_config_save_bundle": "",
"npm_config_shell": "/bin/bash",
"_": "/usr/bin/npm",
"npm_package_dependencies__types_xml2js": "^0.4.5",
"npm_package_dependencies_express": "^4.17.1",
"npm_config_dry_run": "",
"npm_config_format_package_lock": "true",
"npm_config_prefix": "/usr",
"npm_config_scope": "",
"npm_config_browser": "",
"npm_config_cache_lock_wait": "10000",
"npm_config_ignore_prepublish": "",
"npm_config_registry": "https://registry.npmjs.org/",
"npm_config_save_optional": "",
"npm_config_searchopts": "",
"npm_config_versions": "",
"XDG_SESSION_ID": "43",
"TERM": "xterm-256color",
"npm_package_dependencies_rss_parser": "^3.7.3",
"npm_config_cache": "/home/ubuntu/.npm",
"npm_config_proxy": "",
"npm_config_send_metrics": "",
"npm_config_global_style": "",
"npm_config_ignore_scripts": "",
"npm_config_version": "",
"npm_config_local_address": "",
"npm_config_viewer": "man",
"npm_config_node_gyp": "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js",
"PATH": "/usr/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/ubuntu/Findus/Backend/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin",
"npm_package_name": "findus-backend",
"npm_config_audit_level": "low",
"npm_config_prefer_offline": "",
"NODE": "/usr/bin/node",
"LC_ADDRESS": "C.UTF-8",
"XDG_RUNTIME_DIR": "/run/user/1000",
"npm_config_color": "true",
"npm_config_sign_git_commit": "",
"npm_package_dependencies_cron": "^1.8.2",
"npm_config_fetch_retry_mintimeout": "10000",
"npm_config_maxsockets": "50",
"npm_config_offline": "",
"npm_config_sso_poll_frequency": "500",
"LANG": "C.UTF-8",
"LC_TELEPHONE": "C.UTF-8",
"npm_config_umask": "0002",
"LS_COLORS": "rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:",
"npm_package_main": "index.js",
"npm_package_dependencies__types_node": "^12.12.25",
"npm_config_fund": "true",
"npm_config_fetch_retry_maxtimeout": "60000",
"npm_config_loglevel": "notice",
"npm_config_logs_max": "10",
"npm_config_message": "%s",
"npm_lifecycle_script": "tsc",
"npm_config_ca": "",
"npm_config_cert": "",
"npm_config_global": "",
"npm_config_link": "",
"LC_NAME": "C.UTF-8",
"SHELL": "/bin/bash",
"npm_package_version": "1.0.0",
"npm_config_access": "",
"npm_config_also": "",
"npm_config_save": "true",
"npm_config_unicode": "true",
"npm_lifecycle_event": "build",
"npm_package_scripts_build": "tsc",
"npm_config_argv": "{\"remain\":[],\"cooked\":[\"run\",\"build\"],\"original\":[\"run\",\"build\"]}",
"npm_config_before": "",
"npm_config_long": "",
"npm_config_production": "",
"npm_config_searchlimit": "20",
"npm_config_unsafe_perm": "true",
"npm_config_update_notifier": "true",
"LESSCLOSE": "/usr/bin/lesspipe %s %s",
"npm_package_author": "",
"npm_package_dependencies_lodash": "^4.17.15",
"npm_config_auth_type": "legacy",
"npm_config_node_version": "12.16.3",
"npm_config_tag": "latest",
"LC_MEASUREMENT": "C.UTF-8",
"npm_package_dependencies__types_express": "^4.17.2",
"npm_config_git_tag_version": "true",
"npm_config_commit_hooks": "true",
"npm_config_script_shell": "",
"npm_config_shrinkwrap": "true",
"LC_IDENTIFICATION": "C.UTF-8",
"npm_package_license": "ISC",
"npm_package_dependencies_googleapis": "^47.0.0",
"npm_package_dependencies_mongoose": "^5.8.1",
"npm_config_fetch_retry_factor": "10",
"npm_config_save_exact": "",
"npm_config_strict_ssl": "true",
"npm_config_dev": "",
"npm_config_globalconfig": "/usr/etc/npmrc",
"npm_config_init_module": "/home/ubuntu/.npm-init.js",
"npm_config_parseable": "",
"PWD": "/home/ubuntu/Findus/Backend",
"npm_package_dependencies__types_mongodb": "^3.3.13",
"npm_config_globalignorefile": "/usr/etc/npmignore",
"npm_execpath": "/usr/lib/node_modules/npm/bin/npm-cli.js",
"SSH_CONNECTION": "5.231.149.16 39054 172.31.45.156 22",
"XDG_DATA_DIRS": "/usr/local/share:/usr/share:/var/lib/snapd/desktop",
"npm_config_cache_lock_retries": "10",
"npm_config_searchstaleness": "900",
"LC_NUMERIC": "C.UTF-8",
"npm_config_node_options": "",
"npm_config_save_prefix": "^",
"npm_config_scripts_prepend_node_path": "warn-only",
"LC_PAPER": "C.UTF-8",
"npm_config_group": "1000",
"npm_config_init_author_email": "",
"npm_config_searchexclude": "",
"npm_package_dependencies__types_cron": "^1.7.1",
"npm_config_git": "git",
"npm_config_optional": "true",
"npm_config_json": "",
"INIT_CWD": "/home/ubuntu/Findus/Backend"
},
"userLimits": {
"core_file_size_blocks": {
"soft": 0,
"hard": "unlimited"
},
"data_seg_size_kbytes": {
"soft": "unlimited",
"hard": "unlimited"
},
"file_size_blocks": {
"soft": "unlimited",
"hard": "unlimited"
},
"max_locked_memory_bytes": {
"soft": 16777216,
"hard": 16777216
},
"max_memory_size_kbytes": {
"soft": "unlimited",
"hard": "unlimited"
},
"open_files": {
"soft": 1048576,
"hard": 1048576
},
"stack_size_bytes": {
"soft": 8388608,
"hard": "unlimited"
},
"cpu_time_seconds": {
"soft": "unlimited",
"hard": "unlimited"
},
"max_user_processes": {
"soft": 3739,
"hard": 3739
},
"virtual_memory_kbytes": {
"soft": "unlimited",
"hard": "unlimited"
}
},
"sharedObjects": [
"linux-vdso.so.1",
"/lib/x86_64-linux-gnu/libdl.so.2",
"/usr/lib/x86_64-linux-gnu/libstdc++.so.6",
"/lib/x86_64-linux-gnu/libm.so.6",
"/lib/x86_64-linux-gnu/libgcc_s.so.1",
"/lib/x86_64-linux-gnu/libpthread.so.0",
"/lib/x86_64-linux-gnu/libc.so.6",
"/lib64/ld-linux-x86-64.so.2"
]
}
4条答案
按热度按时间iqxoj9l91#
在
NODE_OPTIONS
中使用--max-old-space-size
对我很有效在
package.json
中添加此选项wljmcqd82#
我需要按照这里的说明创建一个交换文件:https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-20-04
2nbm6dog3#
如果您对Typescript类型分析不感兴趣(例如,当一个人不是在开发,而是在安装软件时),您可以使用
transpileOnly: true
禁用它。在
.tsconfig
中看起来像这样:这解决了我在通过Webpack编译TS项目时遇到的类似问题。
w1e3prcc4#
最后,我通过在服务器上使用更多的RAM来修复它。
在我看来,这是一个解决方案。以前不管用,现在管用了。它不仅仅是一个软件解决方案。
我的服务器有512MB的内存或东西,这是非常低的,为我们的时间。Node只需要运行更多。也许有不同的解决方案,您可以在低规格的环境中运行所需的步骤,但对我来说,这是最简单的解决方案。