funboost

repository·master·Indexed 21 days ago

https://github.com/ydf0509/funboost

A Python distributed function scheduling platform for executing and managing functions across distributed systems. It features a FaaS implementation via FastAPI for HTTP-based task interaction, multiple concurrency pool types (including FlexibleThreadPool, AsyncPoolExecutor, and gevent/eventlet), and extensibility through Mixin classes for features like OpenTelemetry distributed tracing and micro-batching.

Tokens
195.8K
Snippets
501
Records
742
Agent score
74%

What's inside funboost

  1. What is Funboost?

    master

    Funboost is a distributed function scheduling platform designed to treat Python functions as first-class citizens. Unlike traditional task queues that focus on background workers, Funboost acts as a FaaS (Function as a Service) microservice platform, bridging the gap between online web business and offline background tasks.

    Key Characteristics:

    • Function-Centric: Moves from URL-based scheduling to direct function-level scheduling.
    • Extensible: Supports 40+ middleware types (e.g., message queues, distributed locks, RPC).
    • Cloud-Native: Designed to provide cloud-native microservice capabilities to Python functions.
    • Async-Native: Full support for the asyncio ecosystem, making it compatible with modern frameworks like FastAPI.
    • Developer Experience Focused: Prioritizes IDE code completion, zero-intrusion, and minimal configuration.
  2. Overview of Celery Canvas orchestration examples

    master

    The test_celery_canvas directory provides examples of complex task orchestrations using Celery Canvas primitives. The examples cover:

    • Primitives: chain, group, and chord.
    • Advanced Patterns: Nested orchestrations, map and starmap usage.
    • Error Handling: Error callbacks, retries, and ignoring errors in a chain.
    • Task Types: HTTP requests, mathematical operations, and video pipelines.
  3. Overview of Funboost Distributed Function Scheduling Platform

    master
    Funboost is a Python-based distributed function scheduling platform. It is designed to manage and execute functions across a distributed environment. For developers looking to integrate or learn the framework, the project provides several key resources including a live demo, full documentation via ReadTheDocs, and specialized AI-ready documentation for rapid development using LLMs.
  4. Introduction to funweb (funboost web manager)

    master

    funweb (funboost_web_manager) is a web-based management interface for the Funboost distributed function scheduling platform. It allows users to:

    • Monitor consumer results and real-time function execution status.
    • Manage queues (clear, pause, resume, adjust QPS, and concurrency).
    • Manage consumers (view by IP or queue name).
    • View real-time and historical consumption speed graphs.
    • Manage scheduled tasks.
    • Perform RPC calls to publish messages to various queue types and retrieve results.
    • Use 'Script Deployment' to manage arbitrary scripts (similar to a lightweight Supervisor/Jenkins/ELK combination).

    Note on Dependencies: funweb does not strictly require MongoDB. If you only use the features that rely on Redis (most features), MongoDB is not necessary.

  5. What is Funboost and when to use it

    master

    Funboost is a general-purpose distributed function scheduling platform for Python. It is designed to be non-intrusive, allowing you to add distributed, high-concurrency, and high-reliability capabilities to any existing function using the @boost decorator without changing your project structure.

    Core Capabilities:

    • Distributed Task Queue: Supports over 40 message brokers (RabbitMQ, Kafka, Redis, MySQL CDC, etc.).
    • FaaS (Function as a Service): Automatically turns decorated functions into HTTP microservices via funboost.faas.
    • High-Performance Concurrency: Supports multiple modes (threading, gevent, eventlet, asyncio, single_thread) and precise QPS (Queries Per Second) control.
    • Reliability: Built-in ACK (acknowledgment) mechanisms, automatic retries, and Dead Letter Queues (DLQ).
    • RPC Mode: Allows synchronous or asynchronous retrieval of function execution results.

    Common Use Cases:

    • Asynchronous Background Tasks: Email/SMS, report generation, video transcoding.
    • Microservices/FaaS: Exposing Python functions as HTTP APIs for cross-language calls (Java/Go/Frontend).
    • Distributed Crawling: High-concurrency web scraping with built-in stability.
    • Data Pipelines/ETL: Real-time data synchronization using MySQL CDC (Binlog).
    • Scheduling: Distributed cron jobs and delayed tasks.
    • IoT: Handling MQTT or TCP/UDP message streams.
  6. Overview of Funboost RPC functionality

    master

    Funboost provides RPC (Remote Procedure Call) capabilities designed to facilitate communication across different environments. This is particularly useful for internal service communication where a full HTTP/REST interface is not required.

    Key use cases for Funboost RPC include communication that is:

    • Cross-process
    • Cross-Python interpreter
    • Cross-server
    • Cross-language

    By replacing standard web interfaces with RPC for non-frontend-facing endpoints, you can reduce boilerplate interface code and improve overall system performance.

  7. Use boost_spider for advanced crawling

    master

    The boost_spider library provides three core classes to simplify crawling tasks while leveraging funboost for distributed scheduling and concurrency:

    1. RequestClient: An enhanced HTTP request class. It wraps requests.Session for cookie persistence and provides built-in support for rotating User-Agents and switching between multiple IP proxy providers automatically.
    2. SpiderResponse: An enhanced response object returned by RequestClient. It allows direct parsing of HTML using .xpath(), .css(), and .re() methods without manual conversion.
    3. DatasetSink: A data persistence class that allows writing Python dictionaries to various databases with a single line of code.
    # Conceptual usage pattern
    from boost_spider import RequestClient
    
    client = RequestClient()
    # Returns a SpiderResponse object
    resp = client.request("https://example.com")
    
    # Direct parsing via SpiderResponse
    title = resp.xpath("//h1/text()")[0]
  8. Use the concurrency pools in Funboost

    master

    Funboost provides several concurrency pool implementations to execute tasks using different concurrency models (threads, coroutines, etc.). All pools implement a submit(fn, *args, **kwargs) API, making them similar to the concurrent.futures module.

    Available pool types include:

    • gevent: Coroutine-based using gevent.
    • eventlet: Coroutine-based using eventlet.
    • asyncio: Coroutine-based using asyncio.
    • CustomThreadPoolExecutor: A variable-bounded thread pool that can automatically expand and shrink the number of threads based on task density.
    • FlexibleThreadPool: The framework's default pool. It is a variable-bounded thread pool that supports both standard def functions and async def coroutines.
    • FixedThreadPool: A simple fixed-size thread pool for long-running tasks that do not need to exit automatically.
    • SoloExecutor: A single-threaded executor (max 1 worker).
    def fun(x):
        print(x)
    
    # Example using a pool
    pool = FlexibleThreadPool(50)
    pool.submit(fun, 1)
  9. Understand the gRPC Demo components

    master

    The gRPC demo consists of the following files:

    • hello.proto: The protobuf definition file that defines the HelloService interface and message formats (including the SayHello method).
    • server.py: The implementation of the gRPC server.
    • client.py: The implementation of the gRPC client.
    • generate_pb.py: A script to compile the .proto file into Python code.
    • requirements.txt: List of Python dependencies required for the demo.
  10. Key advantages of Funboost over Celery

    master

    Funboost is a distributed function scheduling platform designed to be more powerful and easier to use than Celery. Key advantages include:

    • Cross-Platform Support: Full support for Windows, Linux, and macOS (unlike Celery, which has limited Windows support).
    • Versatile Brokers: Supports a wider range of message queues including Kafka, NSQ, MQTT, ZeroMQ, RocketMQ, and Pulsar, in addition to everything Celery/Kombu supports (Redis, RabbitMQ, etc.). It can even use memory, files, or databases as brokers.
    • High Performance: Claims significantly higher performance in both publishing and consuming tasks.
    • IDE Integration: Optimized for PyCharm/VSCode with full auto-completion for methods and parameters (e.g., fun.clear, fun.publish, fun.consume).
    • Simplified Execution: No complex CLI commands required; tasks can be started directly via python xx.py.
    • Flexible Directory Structure: No strict folder hierarchy or centralized app instance required, avoiding circular import issues common in Celery.
    • Native Asyncio Support: Directly supports async def functions without manual loop management.
    • Advanced Control: Supports distributed global QPS rate limiting, multi-process + multi-thread/coroutine stacking, and remote deployment via Fabric.
  11. Understand the limitations of the beggar version implementation

    master

    The beggar_version_implementation is a highly simplified version of the Funboost framework designed solely to demonstrate the core concept of how Python functions are executed in a distributed manner.

    Warning: Do not use this version for production or real projects as it lacks critical features found in the full version.

    Key differences and limitations compared to the full Funboost framework:

    • Concurrency: Only supports multi-threading concurrency. The full version supports 5 different concurrency types.
    • Function Control: Does not support any of the 20 function auxiliary controls (such as rate limiting, timeout killing, or consumer acknowledgment). The full version provides 15+ such features.
    • Middleware: Only demonstrates redis as a message queue middleware. The full version supports 30 different message queue middlewares.
  12. Compare crawler implementation strategies

    master

    Funboost provides several ways to implement crawling and task scheduling, depending on your requirements for complexity, distributed capabilities, and existing code compatibility.

    • boost_spider (👑 Preferred): Combines Funboost with RequestClient. It follows a FaaS (Function-as-a-Service) philosophy, offering minimal code and out-of-the-box distributed support. It is the highest-rated option across almost all dimensions including scheduling, state management, and scalability.

    Alternative Approaches

    • boost_scrapy: A compatibility layer for users migrating from Scrapy, using the Funboost engine with a Scrapy-style API. Recommended only if you have significant existing Scrapy logic.
    • Feapder: A specialized distributed crawler framework with strong automatic database entry features.
    • Scrapy: The traditional framework; lacks external task injection capabilities and is considered less flexible for modern distributed needs.
    • Celery: A general-purpose distributed task queue. While powerful, it is often considered 'overkill' for simple crawling due to complex configuration and worker management.
    • ThreadPool / Redis+Thread: Low-level manual implementations (using concurrent.futures or custom Redis logic). These are suitable only for single-machine learning or very simple scripts and lack robust error handling or distributed scaling.
    | 方式 | 目录 | 核心技术 | 一句话评价 |
    |:---|:---|:---|:---|
    | **boost_spider** 👑 | `boost_spider_imp` | Funboost + RequestClient | **首选**!FaaS 降维打击,极简代码,分布式开箱即用 |
    | **boost_scrapy** | `boost_scrapy_imp` | Funboost 引擎 + Scrapy 风格 API | 照顾 Scrapy 遗老的兼容层,非必要不推荐 |
    | **Feapder** | `feapder_imp` | 国产分布式爬虫框架 | 优秀的垂直框架,自动入库功能很棒 |
    | **Scrapy** | `scrapy_imp` | 传统 Scrapy 框架 | 曾经的王者,现在略显过时,无法外部注入任务 |
    | **Celery** | `celery_imp` | Celery 分布式任务队列 | 杀鸡用牛刀,配置繁琐,worker 启动麻烦 |
    | **Redis+Thread** | `threadpool_redis_crawler_imp` | 手写 Redis + ThreadPool | 400行代码实现1行功能,维护噩梦 |
    | **ThreadPool** | `threadpool_crawler_imp` | Python concurrent.futures | 单机玩具,进程死任务丢,仅限学习 |