From 6d7ee987213990d610de423f7fc64d400f522cc3 Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Tue, 13 Mar 2018 08:54:52 -0700 Subject: [PATCH] Force Tesseract 4 to be single threaded Gives better performance (throughput basis) than the existing solution and scales better on powerful boxes. --- ocrmypdf/__main__.py | 7 +++++++ ocrmypdf/pipeline.py | 6 ------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ocrmypdf/__main__.py b/ocrmypdf/__main__.py index 94412453..c3a006da 100755 --- a/ocrmypdf/__main__.py +++ b/ocrmypdf/__main__.py @@ -730,6 +730,13 @@ def run_pipeline(): # options.input_file, options.pdf_renderer are already bound.) if not options.jobs: options.jobs = available_cpu_count() + + # Performance is improved by setting Tesseract to single threaded. In tests + # this gives better throughput than letting a smaller number of Tesseract + # jobs run multithreaded. + if tesseract.v4(): + os.environ.setdefault('OMP_THREAD_LIMIT', '1') + try: work_folder = mkdtemp(prefix="com.github.ocrmypdf.") options.history_file = os.path.join( diff --git a/ocrmypdf/pipeline.py b/ocrmypdf/pipeline.py index afda0f34..6202f01b 100644 --- a/ocrmypdf/pipeline.py +++ b/ocrmypdf/pipeline.py @@ -1105,8 +1105,6 @@ def build_pipeline(options, work_folder, log, context): extras=[log, context]) task_ocr_tesseract_hocr.graphviz(fillcolor='"#00cc66"') task_ocr_tesseract_hocr.active_if(options.pdf_renderer == 'hocr') - if tesseract.v4(): - task_ocr_tesseract_hocr.jobs_limit(2) # Uses multi-core on its own task_select_visible_page_image = main_pipeline.collate( task_func=select_visible_page_image, @@ -1159,8 +1157,6 @@ def build_pipeline(options, work_folder, log, context): extras=[log, context]) task_ocr_tesseract_textonly_pdf.graphviz(fillcolor='"#ff69b4"') task_ocr_tesseract_textonly_pdf.active_if(options.pdf_renderer == 'sandwich') - if tesseract.v4(): - task_ocr_tesseract_textonly_pdf.jobs_limit(2) task_combine_layers = main_pipeline.collate( task_func=combine_layers, @@ -1184,8 +1180,6 @@ def build_pipeline(options, work_folder, log, context): extras=[log, context]) task_ocr_tesseract_and_render_pdf.graphviz(fillcolor='"#66ccff"') task_ocr_tesseract_and_render_pdf.active_if(options.pdf_renderer == 'tesseract') - if tesseract.v4(): - task_ocr_tesseract_and_render_pdf.jobs_limit(2) # Uses multi-core # PDF/A task_generate_postscript_stub = main_pipeline.transform(