我们正在使用 FastReport 生成报告,当我们在 Windows 机器上进行开发时,可以生成大小为 +10 页的 pdf 文件,但是当我们发布它(目标运行时 - Linux x64)并将其移动到我们的 Centos8 实例(使用 nginx 运行 - 在 systemd 服务上)时,大于 +- 2 pdf 页的报告将导致内存不足异常。
我想知道这是什么原因造成的?可能是因为 systemd 服务受到限制吗?
我已采取的步骤:
联系了 FastReport 支持,他们为我们提供了一个解决方法,但这也导致了内存不足异常 - 我认为这不是他们的错,因为它在我们的开发 Windows 机器上运行良好 - 也许 Linux 服务器的配置不正确
尝试在机器上添加更多 RAM(目前为 16 GB RAM 和 16 GB 交换 - 开发机器有 16 GB)
尝试使用 top / htop 命令跟踪内存使用情况,我注意到该服务仅使用了 1% 的可用 RAM
尝试使用 ulimits 来尝试增加最大可用资源(目前这里不再进行任何编辑 - 我决定删除我的更改,因为我对 ulimits 不太熟悉,所以保留所做的更改让我感到不太舒服)
我的服务(目前使用用户 root 来测试这个 - 如果我错了请纠正我,但是 root 是否能够在需要时获取所有可用的资源?)
[Unit]
Description=fastreport
[Service]
WorkingDirectory=/var/www/fastreport/
ExecStart=/usr/bin/dotnet /var/www/fastreport/YinaPrintingService.dll
Restart=always
RestartSec=10
SyslogIdentifier=fastreport
User=root
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
Environment=ASPNETCORE_URLS=http://localhost:9999;
[Install]
WantedBy=multi-user.target
journalctl 中的错误
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: fail: Microsoft.AspNetCore.Server.Kestrel[13]
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: Connection id "0HMBHT8G3SG2D", Request id "0HMBHT8G3SG2D:00000002": An unhandled exception was thrown by the application.
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: System.OutOfMemoryException: Out of memory.
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: at System.Drawing.Graphics.Save()
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: at FastReport.GdiGraphics.Save()
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: at FastReport.TextObject.CalcSize()
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: at FastReport.TextObject.CalcHeight()
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: at FastReport.Table.TableCellData.CalcHeight(Single width)
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: at FastReport.Table.TableBase.CalcHeight()
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: at FastReport.BandBase.CalcHeight()
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: at FastReport.Engine.ReportEngine.PrepareBand(BandBase band, Boolean getData)
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: at FastReport.Engine.ReportEngine.ShowBandToPreparedPages(BandBase band, Boolean getData)
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: at FastReport.Engine.ReportEngine.ShowBand(BandBase band, Boolean getData)
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: at FastReport.Engine.ReportEngine.ShowBand(BandBase band)
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: at FastReport.Engine.ReportEngine.RunDataBand(DataBand dataBand, Int32 rowCount, Boolean keepFirstRow, Boolean keepLastRow)
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: at FastReport.Engine.ReportEngine.RunDataBand(DataBand dataBand)
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: at FastReport.Engine.ReportEngine.RunBands(BandCollection bands)
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: at FastReport.Engine.ReportEngine.RunReportPage(ReportPage page)
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: at FastReport.Engine.ReportEngine.RunReportPages()
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: at FastReport.Engine.ReportEngine.RunReportPages(ReportPage page)
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: at FastReport.Engine.ReportEngine.Run(Boolean runDialogs, Boolean append, Boolean resetDataState, ReportPage page)
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: at FastReport.Engine.ReportEngine.Run(Boolean runDialogs, Boolean append, Boolean resetDataState)
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: at FastReport.Report.Prepare(Boolean append)
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: at YinaPrintingService.Utilities.ProductieLijstTemplateUtility.GetProductieLijstRechts(List`1 dtos) in C:\Users\glenn\Source\Repos\fastreportprinting\YinaPrintingService\Utilities\ProductieLijstTemplateUtility.cs:line 315
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: at YinaPrintingService.Factories.ProductieLijstRechtsFromCodeFactory.GenerateReport(JArray array) in C:\Users\glenn\Source\Repos\fastreportprinting\YinaPrintingService\Factories\ProductieLijstRechtsFromCodeFactory.cs:line 11
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: at YinaPrintingService.Controllers.DocumentController.Index(JArray array, FastReportDocumentTemplate templateName, String printerName, OutputMode outMode) in C:\Users\glenn\Source\Repos\fastreportprinting\YinaPrintingService\Controllers\DocumentController.cs:line 47
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: at lambda_method1(Closure , Object , Object[] )
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: --- End of stack trace from previous location ---
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: at FastReport.Web.FastReportMiddleware.Invoke(HttpContext httpContext)
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
Sep 07 13:31:44 localhost.localdomain fastreport[5835]: at Micr
其他信息:
[root@localhost fastreport]# lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 4
On-line CPU(s) list: 0-3
Thread(s) per core: 2
Core(s) per socket: 2
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
BIOS Vendor ID: None
CPU family: 6
Model: 85
Model name: Intel(R) Xeon(R) Silver 4208 CPU @ 2.10GHz
BIOS Model name: None
Stepping: 7
CPU MHz: 2095.079
BogoMIPS: 4190.15
Hypervisor vendor: Microsoft
Virtualization type: full
L1d cache: 32K
L1i cache: 32K
L2 cache: 1024K
L3 cache: 11264K
NUMA node0 CPU(s): 0-3
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology cpuid pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid mpx avx512f avx512dq rdseed adx smap clflushopt clwb avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves avx512_vnni md_clear flush_l1d arch_capabilities
[root@localhost fastreport]# free -m
total used free shared buff/cache available
Mem: 15401 1466 13469 16 465 13650
Swap: 16055 0 16055
[root@localhost fastreport]# uname -a
Linux localhost.localdomain 4.18.0-338.el8.x86_64 #1 SMP Fri Aug 27 17:32:14 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux