gristlabs_grist-core/test
Dmitry S d191859be7 (core) For exporting XLSX, do it memory-efficiently in a worker thread.
Summary:
- Excel exports were awfully memory-inefficient, causing occasional docWorker
  crashes. The fix is to use the "streaming writer" option of ExcelJS
  https://github.com/exceljs/exceljs#streaming-xlsx-writercontents. (Empirically
  on one example, max memory went down from 3G to 100M)
- It's also CPU intensive and synchronous, and can block node for tens of
  seconds. The fix is to use a worker-thread. This diff uses "piscina" library
  for a pool of threads.
- Additionally, adds ProcessMonitor that logs memory and cpu usage,
  particularly when those change significantly.
- Also introduces request cancellation, so that a long download cancelled by
  the user will cancel the work being done in the worker thread.

Test Plan:
Updated previous export tests; memory and CPU performance tested
manually by watching output of ProcessMonitor.

Difference visible in these log excerpts:

Before (total time to serve request 22 sec):
```
Telemetry processMonitor heapUsedMB=2187, heapTotalMB=2234, cpuAverage=1.13, intervalMs=17911
Telemetry processMonitor heapUsedMB=2188, heapTotalMB=2234, cpuAverage=0.66, intervalMs=5005
Telemetry processMonitor heapUsedMB=2188, heapTotalMB=2234, cpuAverage=0, intervalMs=5005
Telemetry processMonitor heapUsedMB=71, heapTotalMB=75, cpuAverage=0.13, intervalMs=5002
```
After (total time to server request 18 sec):
```
Telemetry processMonitor heapUsedMB=109, heapTotalMB=144, cpuAverage=0.5, intervalMs=5001
Telemetry processMonitor heapUsedMB=109, heapTotalMB=144, cpuAverage=1.39, intervalMs=5002
Telemetry processMonitor heapUsedMB=94, heapTotalMB=131, cpuAverage=1.13, intervalMs=5000
Telemetry processMonitor heapUsedMB=94, heapTotalMB=131, cpuAverage=1.35, intervalMs=5001
```
Note in "Before" that heapTotalMB goes up to 2GB in the first case, and "intervalMs" of 17 seconds indicates that node was unresponsive for that long. In the second case, heapTotalMB stays low, and the main thread remains responsive the whole time.

Reviewers: jarek

Reviewed By: jarek

Differential Revision: https://phab.getgrist.com/D3906
2023-06-01 12:06:48 -04:00
..
client (core) Minimazing widgets 2023-03-02 11:22:49 +01:00
common (core) Fix the empty values last option in multicol sorting 2023-01-31 12:14:22 +01:00
deployment Adding new lines at the end 2022-09-30 17:00:38 +02:00
fixtures (core) For exporting XLSX, do it memory-efficiently in a worker thread. 2023-06-01 12:06:48 -04:00
formula-dataset add support for conversational state to assistance endpoint (#506) 2023-05-08 14:15:22 -04:00
gen-server (core) Persist forks in home db 2023-02-20 22:46:36 -05:00
nbrowser (core) Fixing DELETE and BACKSPACE keys on ChoiceList and RefList editor. 2023-06-01 16:53:38 +02:00
server (core) updates from grist-core 2023-05-30 08:32:34 -04:00
timings run grist-core test batches in parallel (#444) 2023-03-03 09:53:33 -05:00
.eslintrc.js Fixing all eslint's reported error 2023-01-03 17:22:58 +01:00
chai-as-promised.js (core) Faster builds all around. 2022-07-04 10:42:40 -04:00
init-mocha-webdriver.js Correct spelling mistakes 2022-02-19 09:46:49 +00:00
mocha.opts run grist-core test batches in parallel (#444) 2023-03-03 09:53:33 -05:00
report-why-tests-hang.js (core) Move report-why-tests-hang helper to core 2021-04-26 23:52:16 -04:00
setupPaths.js add test/upgradeDocument utility 2023-01-17 16:14:15 -05:00
split-tests.js run grist-core test batches in parallel (#444) 2023-03-03 09:53:33 -05:00
test_under_docker.sh Adding dedicated folder for external tests 2022-09-30 16:45:35 +02:00
testUtils.ts (core) add missing tsconfig file that affects IDEs 2022-05-27 13:48:58 -04:00
tsconfig.json (core) Faster builds all around. 2022-07-04 10:42:40 -04:00
upgradeDocument add test/upgradeDocument utility 2023-01-17 16:14:15 -05:00
upgradeDocumentImpl.ts add test/upgradeDocument utility 2023-01-17 16:14:15 -05:00
utils.js (core) Moving client and common tests to core 2022-08-23 19:20:10 +02:00
xunit-file.js (core) Parallelize jenkins by running on multiple machines. 2022-07-01 16:18:36 -04:00