Skip to content

Commit

Permalink
perf(plugins/image-to-txt): use logical core count
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdawgs committed Apr 30, 2024
1 parent 4f1af67 commit 55ce1a2
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 71 deletions.
4 changes: 2 additions & 2 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ AUTH_BEARER_TOKEN_ARRAY=
OCR_ENABLED=

# The number of Tesseract workers to create.
# Defaults to counting the number of physical cores on the machine
# and creating an equal number of workers
# Defaults to using number of logical CPUs on the system
# (-1 to account for the main thread) and creating an equal number of workers
OCR_WORKERS=

# Languages to load trained data for for the `ocr` query string param
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"author": "Frazer Smith <frazer.dev@outlook.com>",
"funding": "https://github.com/sponsors/Fdawgs",
"engines": {
"node": ">=18.12.1"
"node": ">=18.14.0"
},
"scripts": {
"benchmark:html": "autocannon -a 100 -m POST -i \"./test_resources/test_files/pdf_1.3_NHS_Constitution.pdf\" -H \"Content-Type:application/pdf\" \"http://0.0.0.0:3000/pdf/html?lastPageToConvert=1\"",
Expand Down
6 changes: 3 additions & 3 deletions src/config/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"use strict";

const { readFile } = require("node:fs/promises");
const { availableParallelism } = require("node:os");
const envSchema = require("env-schema");
const { getStream } = require("file-stream-rotator");
const S = require("fluent-json-schema").default;
const { stdSerializers, stdTimeFunctions } = require("pino");
const { parse: secureParse } = require("secure-json-parse");
const { dirname, joinSafe, normalizeTrim } = require("upath");

const coreCount = require("../utils/core-count");
const { description, license, version } = require("../../package.json");

/**
Expand Down Expand Up @@ -330,8 +330,8 @@ async function getConfig() {
tesseract: {
enabled: env.OCR_ENABLED === true,
languages: env.OCR_LANGUAGES || "eng",
// Use number of physical CPU cores available if ENV variable not specified
workers: env.OCR_WORKERS || coreCount(),
// Use all but one core for OCR workers to prevent blocking the event loop if ENV variable not specified
workers: env.OCR_WORKERS || availableParallelism() - 1,
},
unrtf: {
tempDir,
Expand Down
54 changes: 0 additions & 54 deletions src/utils/core-count/index.js

This file was deleted.

11 changes: 0 additions & 11 deletions src/utils/core-count/util.test.js

This file was deleted.

0 comments on commit 55ce1a2

Please sign in to comment.