Requirements and estimate the number of Docker Swarm node for OCR conversion
- Mohammed Jassim Jasmin

- Mar 31
- 2 min read
requirements and estimate the number of Docker Swarm nodes you'll need for your Flask API with image-to-OCR using Tesseract
Understanding the Resource Requirements:
CPU: Tesseract is CPU-intensive, especially when processing large images or PDFs.
RAM: Handling 15MB images and potentially PDFs requires sufficient RAM, especially during processing.
Network: Transferring 15MB of data per request can put a strain on your network bandwidth.
Concurrent Requests: You anticipate 20 concurrent requests.
Estimating Resource Usage:
CPU Usage:
OCR processing is a CPU-bound task. Each request will likely consume significant CPU resources.
With 4 cores per machine, you need to distribute the load effectively.
RAM Usage:
Loading and processing 15MB images and PDFs will consume a substantial amount of RAM.
You'll need to consider the memory footprint of the Flask application, Tesseract, and any intermediate data structures.
Network Usage:
20 requests * 15MB = 300MB of data transfer per second (if they all arrive simultaneously). This requires a robust network connection.
Docker Swarm Setup:
Resource Allocation:
With 8GB of RAM, you might be able to allocate 1-2GB per container, depending on the efficiency of your Flask application and Tesseract.
With 4 CPU cores, you can allocate 1-2 cores per container.
Container Replication:
To handle 20 concurrent requests, you'll need multiple container replicas.
A conservative approach would be to aim for 2-3 replicas per node, to maintain some redundancy.
Node Utilization:
You want to avoid overloading any single node.
Distribute the load evenly across your 5 machines.
Calculations and Recommendations:
Replicas per Node:
If each replica can handle 5-10 concurrent requests, you'll need 2-4 replicas to handle 20 requests.
Total Replicas:
To be safe, I would recommend to start with 10 replicas. This will allow for some head room, and if the processing of the images takes a long time, allow for new requests to be processed.
Distribution:
Docker Swarm will distribute these replicas across your 5 nodes.
This equates to 2 replicas per machine.
Testing:
Load testing is crucial. Use tools like locust or jmeter to simulate the expected load and monitor your system's performance.
Monitor CPU, RAM, and network usage during testing.
Adjust the number of replicas and resource allocations as needed.
Docker Swarm Considerations:
Load Balancing: Docker Swarm's built-in load balancing will distribute requests across your replicas.
Resource Limits: Set resource limits (CPU and RAM) for your Docker containers to prevent them from consuming excessive resources.
Monitoring: Implement monitoring tools to track the performance of your Docker Swarm and containers.
Network: Ensure a high-bandwidth, low-latency network connection between your Docker Swarm nodes.
Storage: If your images and PDFs are stored on a shared volume, ensure that the storage system can handle the concurrent access.
Conclusion:
With 5 machines, you should be able to handle the load, but thorough testing is essential.
Start with 2 replicas per machine.
Monitor resource usage and adjust the number of replicas as needed.
Load testing is crucial.
Remember that these are estimations. The actual resource usage will depend on the complexity of your OCR tasks and the efficiency of your code.





Comments