README.md

Unlimited Translator (ULT)

README on languages: English, Russian

Unlimited Translator (ULT) is a FastAPI-based service offering unlimited text translation capabilities. Powered by deep_translator, ULT supports automatic language detection and a wide range of target languages. Its design ensures scalability, making it ideal for applications requiring high-volume or continuous translations without constraints. ULT seamlessly integrates into modern workflows, providing fast and reliable translations for users worldwide.

Features

  • Translate text into any supported language.
  • Automatic source language detection.
  • RESTful API for hassle-free integration.

Requirements

  • Python 3.8 or later
  • FastAPI
  • Pydanttic
  • Uvicorn
  • Deep Translator

Installation

  1. Clone the repository:

    git clone https://ilyazheproghub.ru/project/ilyazheprog/ult.git
    cd ult
    
  2. Create and activate a virtual environment:

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
    
  3. Install the dependencies:

    pip install -r requirements.txt
    

Running ULT

To start the server, simply run:

python main.py

This will launch the application on http://127.0.0.1:8000.

Here’s the updated section with a detailed explanation of how to choose the number of workers based on workload:


How Does It Work?

  • The main.py file contains the entry point for the application:

    if __name__ == "__main__":
      uvicorn.run("api:app", host="0.0.0.0", port=8000, workers=6)
    
  • By default:
    • The application binds to all network interfaces (0.0.0.0).
    • It listens on port 8000.
    • Six worker processes are started for handling concurrent requests.

Choosing the Number of Workers

The number of workers (--workers) defines how many processes will run your FastAPI application. More workers allow the application to handle more simultaneous requests but use more server resources. The choice depends on:

  1. Type of Tasks:

    • I/O-bound tasks (like this translation service):
      • Tasks like calling external APIs or reading files often leave the CPU idle while waiting for a response.
      • Use more workers than CPU cores to maximize resource utilization.
    • CPU-bound tasks:
      • Heavy calculations or data processing require significant CPU time.
      • Match the number of workers to the number of available CPU cores.
  2. Expected Traffic:

    • Low traffic:
      • 1-2 workers are sufficient for lightweight, low-traffic applications.
    • Moderate traffic:
      • Use 1 worker per CPU core (e.g., 4 workers for a 4-core server).
    • High traffic:
      • For I/O-bound workloads, use 1.5-2x the number of CPU cores to handle bursts of requests.
  3. Server Resources:

    • Ensure the server has enough RAM to support the number of workers.
    • Each worker is a separate process and consumes memory.

Why Six Workers?

In this case:

  • The translation service is I/O-bound, making it suitable to oversubscribe workers relative to CPU cores.
  • Six workers ensure efficient handling of concurrent translation requests, especially on multi-core servers.

Rule of Thumb

  • The higher the number of simultaneous requests, the more workers you should configure (within the limits of your server’s resources).
  • Monitor performance (e.g., CPU usage, response times) and adjust the number of workers as needed.

API Endpoints

POST /translate

Translate text into the specified language.

Request Body:

{
  "text": "Hello, world!",
  "to": "es"
}

Response:

  • Success:

    {
      "translatedText": "Hola, mundo!",
      "status": true,
      "message": "Translation successful"
    }
    
  • Error:

    {
      "translatedText": null,
      "status": false,
      "message": "An unexpected error occurred during translation."
    }
    

License

This project is licensed under the GNU General Public License (GPL). See the LICENSE file for details.

Конвейеры
0 успешных
0 с ошибкой