Hippo4j Documentation

repository·develop·Indexed 27 days ago

https://github.com/opengoofy/hippo4j

Hippo4j is a dynamic and observable thread pool management framework for Java designed to improve system reliability. It provides real-time monitoring, dynamic parameter adjustment (core/max threads, queue capacity, rejection policies), and automated alerting. It supports global management, context propagation, and graceful shutdown, with adapters for third-party frameworks including Dubbo, RabbitMQ, RocketMQ, and SpringCloud Stream RocketMQ. Deployment options include dependency on configuration centers like Nacos or using the standalone hippo4j-server.

Tokens
37K
Snippets
48
Records
239
Agent score
91%

What's inside Hippo4j

  1. Overview of Hippo4j

    develop

    Hippo4j is a dynamically observable thread pool management framework designed to improve system reliability. It addresses common thread pool pain points such as resource exhaustion, difficult parameter estimation, lack of monitoring, and task accumulation.

    Key features include:

    • Global Management: Manage application thread pool instances.
    • Dynamic Configuration: Change parameters like core/max threads, queue capacity, and rejection policies at runtime.
    • Alerting: Built-in notification strategies for thread pool activity, capacity watermarks, rejection policies, and long-running tasks.
    • Data Collection: Supports Prometheus, InfluxDB, ElasticSearch, logs, and built-in collection.
    • Monitoring: Real-time runtime data visualization.
    • Context Propagation: Supports passing thread-local contexts (e.g., MDC) to tasks.
    • Graceful Shutdown: Supports waiting for tasks to complete within a specified time during project shutdown.
    • Framework/Container Support: Adapts to Tomcat, Jetty, Undertow, Dubbo, Hystrix, RabbitMQ, and RocketMQ.
  2. Overview of Hippo4j features

    develop

    Hippo4j enhances JDK thread pools and extends third-party framework thread pools to improve the operational reliability of business systems.

    Key capabilities include:

    • Global Management: Manage application thread pool instances.
    • Dynamic Configuration: Change parameters at runtime, including core pool size, maximum pool size, blocking queue capacity, and rejection policies.
    • Alerting: Built-in notification strategies for thread pool activity, capacity watermarks, rejection policies, and excessively long task execution times.
    • Monitoring: Real-time viewing of runtime data and charts for the last 30 minutes of operation.
    • Functional Extensions: Support for task context propagation (e.g., MDC) and graceful shutdown (waiting for tasks to complete within a specified time).
    • Deployment Modes: Supports both Configuration Center Dependency mode and Middleware-free mode.
    • Container & Framework Support: Monitor and modify thread counts for Tomcat, Jetty, Undertow, Dubbo, Hystrix, RabbitMQ, and RocketMQ.
  3. Understand Hippo4j core features and architecture

    develop

    Hippo4j is a lightweight, dynamic, and observable thread pool management system designed to enhance native Java thread pools. It addresses common production issues such as improper parameter configuration, lack of monitoring, task accumulation, and loss of context (e.g., MDC) during asynchronous execution.

    Key Problems Solved:

    • Resource Management: Prevents high server load caused by excessive thread resources.
    • Parameter Tuning: Enables dynamic adjustment of thread pool parameters to match business concurrency.
    • Observability: Provides visibility into task execution times, task accumulation, and rejection strategies.
    • Context Propagation: Supports passing runtime variables (like MDC context) to threads.
    • Graceful Shutdown: Ensures running tasks are not discarded when the application shuts down.
    • Deadlock Detection: Helps identify tasks that stop executing due to deadlocks or long-running operations.

    Management Hierarchy:

    Hippo4j organizes thread pools using a hierarchical structure: Tenant $\rightarrow$ Project $\rightarrow$ Thread Pool. This allows for granular control and permission management across different teams and services.

  4. Understand Hippo4j developer roles

    develop

    Hippo4j defines three primary developer roles based on contribution level and repository access:

    1. Maintainer: Core developers who design and develop key modules, maintain the community (Issues, PRs, website), and mentor other developers.
    2. Committer: Individuals with write access to the Hippo4j repository. They provide continuous contributions via Issues and PRs, participate in feature discussions, and perform code reviews.
    3. Contributor: Individuals who have had at least one Pull Request (code or documentation) merged into the project.
  5. Understand Hippo4j Deployment Roles

    develop

    Hippo4j operates using two distinct roles to provide dynamic thread pool observability and management:

    • Server Side: A standalone Java process that manages user permissions, monitors thread pools, and executes persistent actions.
    • Client Side: Your SpringBoot application, which integrates the Hippo4j-Spring-Boot-Starter JAR to interact with the Server side. The Client is responsible for pulling thread pool data, receiving dynamic configuration updates, and reporting runtime metrics.
  6. Follow punctuation and character usage conventions

    develop

    Adhere to these punctuation and character standards for professional documentation:

    • Avoid repeating punctuation: Do not use multiple exclamation or question marks to emphasize emotion.
      • Correct: 德國隊竟然戰勝了巴西隊!
      • Incorrect: 德國隊竟然戰勝了巴西隊!!
    • Use Full-width (全形) Chinese punctuation: Use standard Chinese punctuation marks for Chinese text.
      • Correct: 嗨!你知道嘛?
      • Incorrect: 嗨! 你知道嘛?
    • Use Half-width (半形) characters for numbers: Use standard half-width digits.
      • Correct: 1000 元
      • Incorrect: 1000 元
    • Use Half-width punctuation for English sentences/proper nouns: When a sentence or specific term is entirely in English, use half-width punctuation.
      • Correct: 「Stay hungry, stay foolish.」
      • Incorrect: 「Stay hungry,stay foolish。」
  7. Best practices for asking technical questions

    develop

    Before asking technical questions via email, newsgroups, or chat rooms, follow these steps to find the answer yourself:

    1. Search for answers in existing posts within the forum you are using.
    2. Search the internet.
    3. Read the manual/documentation.
    4. Read the FAQ (Frequently Asked Questions).
    5. Perform your own checks or experiments.
    6. Ask experienced colleagues or friends.
    7. If you are a developer, attempt to read the source code.

    When you do ask a question, explicitly state the efforts you have already made. This demonstrates that you are not wasting others' time and helps establish you as a learner.

  8. Dynamically change thread pool configurations

    develop

    You can modify dynamic thread pool parameters through the Hippo4j Server Console.

    1. Navigate to the Dynamic Thread Pool (动态线程池) menu in the console.
    2. Select the specific thread pool instance you wish to modify.
    3. Update the parameters and apply changes.

    When deploying a Client cluster, you can choose to modify a single specific instance or use the 全部修改 (Modify All) button to apply changes to all instances in the cluster simultaneously.

    Successful configuration changes will be reflected in the application logs. A successful change log entry will look similar to this:

    2022-09-10 00:23:29.783  INFO 50322 --- [change.config_0] c.h.s.s.c.ServerThreadPoolDynamicRefresh : [message-consume] Dynamic thread pool change parameter.
        corePoolSize: 2 => 4
        maximumPoolSize: 6 => 12
        capacity: 1024 => 2048
        keepAliveTime: 9999 => 9999
        executeTimeOut: 800 => 3000
        rejectedType: SyncPutQueuePolicy => RunsOldestTaskPolicy
        allowCoreThreadTimeOut: true => true
  9. Choose the best BlockingQueue for your use case

    develop

    Use the following recommendations when selecting a queue type for your Hippo4j executor:

    RequirementRecommended Queue Type
    Dynamic capacity adjustmentResizableCapacityLinkedBlockingQueue
    Strictly boundedArrayBlockingQueue
    Unbounded throughputLinkedBlockingQueue
    Priority-based processingPriorityBlockingQueue
    Synchronous hand-offSynchronousQueue