r-nacos Documentation

repository·master·Indexed 23 days ago

https://github.com/nacos-group/r-nacos

A high-performance, Rust-based re-implementation of the Nacos service discovery and configuration management platform. Designed as a drop-in replacement for Java-based Nacos, it maintains compatibility with Nacos 1.x (HTTP) and 2.x (gRPC) protocols while offering lower resource consumption and faster startup times. Features include a service registry, configuration center, MCP service, and a web management console.

Tokens
22.7K
Snippets
39
Records
125
Agent score
79%

What's inside r-nacos

  1. Overview of nacos_rust_client

    master

    The nacos_rust_client is a Rust implementation of the Nacos client SDK. It is designed for high performance and stability, utilizing actix and tokio for asynchronous operations. All client background processing occurs within a single actix environment thread to prevent thread explosion and ensure controllable resource usage.

    Key capabilities include:

    • Config Center: Supports pushing, retrieving, and listening to configurations.
    • Naming Service: Supports service instance registration (with automatic heartbeat maintenance) and service instance retrieval (with automatic listening/caching of instance lists).

    Protocol Support:

    • v0.3.x and later: Supports both Nacos 1.x (HTTP) and 2.x protocols. You can specify the protocol type when creating the client.
    • v0.2.x: Only supports Nacos 1.x (HTTP) protocol.

    Note: v0.3.x is backward compatible with v0.2.x APIs. It is recommended to upgrade to v0.3.x.

  2. Overview of r-nacos

    master

    r-nacos is a lightweight, fast, stable, and high-performance implementation of the Nacos service written in Rust. It provides the following core functionalities:

    • Service Registry: Manages service instances.
    • Configuration Center: Manages application configurations.
    • MCP Service: Built-in MCP (Model Context Protocol) server and interface forwarding. It can transform standard HTTP interfaces registered in r-nacos into MCP services.
    • Web Management Console: A UI for managing the service.

    Key Features:

    • Protocol Compatibility: Fully compatible with the latest Nacos client SDK protocols, including Nacos 1.x (HTTP OpenApi) and Nacos 2.x (gRPC). This allows applications to migrate to r-nacos without code changes.
    • Efficiency: Compared to the Java-based Nacos, r-nacos offers faster startup times, lower system resource consumption, and higher performance.
    • Deployment: Supports both standalone and cluster deployments.
  3. Use the rnacos load testing tool

    master

    The loadtest project is a performance testing tool built on goose designed to benchmark rnacos service interfaces. It can be used to establish performance baselines, assist in optimization, and compare performance between rnacos and the standard Java Nacos server.

    Currently, the tool supports testing via the HTTP protocol. gRPC testing support is planned but not yet implemented.

  4. Console and Deployment Features in r-nacos

    master

    r-nacos includes management capabilities for both administrative tasks and infrastructure deployment.

    Web Console Features

    • Namespaces: Manage namespace lists and switch namespaces to query configuration and service data.
    • Configuration Management: Manage configuration information, import/export configurations (using Nacos-compatible formats), and view/restore configuration history.
    • Service Management: Manage services and service instances.
    • Limitations: Authentication is currently disabled in the console. Advanced tag queries, configuration listener logs, and service listener logs are not yet supported.

    Deployment and Clustering

    • Standalone Mode: Supports single-node deployment.
    • Cluster Mode: Supports cluster deployment. For cluster configuration, r-nacos uses a distributed storage system composed of Raft + local node storage, meaning it does not require an external MySQL dependency for configuration data.
  5. Performance and Capacity Overview

    master

    r-nacos provides high-performance configuration and naming services. Performance characteristics vary significantly between the HTTP (v1.x) and gRPC (v2.x) protocols, especially regarding heartbeat mechanisms and capacity.

    Key Capacity Insights

    Configuration Center

    • Querying: High single-node performance (~80k QPS) with horizontal scalability. No significant bottleneck in clusters.
    • Memory: Usage is proportional to the amount of configuration data; performance is stable until memory limits are reached.
    • Writing: Currently, writes are handled by the master node, which may present a bottleneck. Optimization is expected to increase write TPS from ~1.5k to over 10k.

    Naming Center (Service Registry)

    • Querying: High single-node performance (~30k QPS) with horizontal scalability.
    • Memory: Usage is proportional to the number of service instances.
    • Protocol Differences:
      • HTTP (v1.x): Heartbeats are calculated per instance and share QPS with service registration. Theoretical capacity is limited to approximately 50,000 service instances (assuming 10k registration/heartbeat QPS and a 5s heartbeat interval).
      • gRPC (v2.x): Heartbeats are calculated per connection and do not pass through the registry's processing threads. This allows for significantly higher capacity. For a 3-node cluster, theoretical support can reach 36 million service instances (assuming 10k registration QPS and 1-hour reconnection intervals) and 1.2 million concurrent connection instances.
  6. SDK Feature Support in r-nacos

    master

    r-nacos provides core functionality for client SDKs, maintaining compatibility with existing Nacos implementations.

    Configuration Center

    • Supports basic configuration management and maintains configuration history.
    • Fully compatible with Nacos Configuration Center SDK protocols.
    • Limitations: Currently does not support grayscale release or tag isolation.

    Service Registry

    • Supports basic service registration and discovery.
    • Fully compatible with Nacos Service Registry SDK protocols.
    • Limitations: Does not support Nacos 1.x UDP-based instance change notifications. It only supports Nacos 2.x gRPC-based real-time instance change notifications.

    Authentication

    • Provides an interface to obtain authentication tokens.
    • Note: Actual requests currently do not enforce authentication (all requests are treated as authenticated).
  7. How the Configuration Center works with Raft

    master

    The Configuration Center in r-nacos is implemented as a Raft state machine using the async-raft library. This ensures strong consistency across a cluster.

    Key Concepts

    • Roles: Nodes are either leader (primary), follower (secondary), or candidate (during elections).
    • Write Flow:
      1. A client sends an update request to any node.
      2. If the node is not the leader, the request is routed to the leader.
      3. The leader writes the request to the Raft log and synchronizes it to followers.
      4. Once a majority of nodes have successfully written the log, the leader commits the change to the state machine (the Configuration Center) and returns the result.
    • Read Flow:
      1. A client sends a query request to any node.
      2. The node queries its local configuration data and returns the result immediately (allowing for local reads).
  8. ToolSpec Data Structure Schema

    master

    ToolSpec data must use the function field for its definition (the older parameters field is deprecated). The function field must contain name, description, and parameters sub-fields.

    Example valid ToolSpec JSON:

    {
      "namespace": "test-namespace",
      "group": "test-group", 
      "toolName": "test-tool",
      "function": {
        "name": "test-tool",
        "description": "Test tool for test-tool",
        "parameters": {
          "input": {
            "type": "object",
            "properties": {
              "query": {
                "type": "string",
                "description": "The query string"
              },
              "limit": {
                "type": "integer", 
                "description": "Maximum number of results"
              }
            },
            "required": ["query"]
          }
        }
      },
      "version": 1
    }
    {
      "namespace": "test-namespace",
      "group": "test-group", 
      "toolName": "test-tool",
      "function": {
        "name": "test-tool",
        "description": "Test tool for test-tool",
        "parameters": {
          "input": {
            "type": "object",
            "properties": {
              "query": {
                "type": "string",
                "description": "The query string"
              },
              "limit": {
                "type": "integer", 
                "description": "Maximum number of results"
              }
            },
            "required": ["query"]
          }
        }
      },
      "version": 1
    }
  9. Understand r-nacos Console and Management features

    master

    The r-nacos console is designed for developers and administrators, featuring a decoupled frontend/backend architecture.

    User and Access Management

    • Manage user lists and roles/permissions.
    • Reset user passwords.
    • Supports LDAP and OAuth2.0 authentication.
    • The console can be configured to use a dedicated port for external network services.

    Namespace and Data Management

    • Namespaces: Manage namespace lists and switch namespaces to query specific configuration or service data.
    • Configuration Center: Manage configuration data, view/restore history, and import/export configurations (compatible with Nacos file formats).
    • Service Center: Manage services and service instances.

    Limitations

    • Does not currently support advanced tag queries or viewing configuration listener records.
    • Does not currently support querying service listener records.
  10. Manage Users and Permissions in r-nacos Console

    master

    The r-nacos console provides granular access control.

    Default Credentials

    • Username: admin
    • Password: admin
    • Customization: Use environment variables RNACOS_INIT_ADMIN_USERNAME and RNACOS_INIT_ADMIN_PASSWORD to change these during initialization.

    User Roles

    1. Administrator (管理员): Full access to all console features.
    2. Developer (开发者): All permissions except User Management.
    3. Visitor (访客): Read-only access to Configuration and Naming data; no editing permissions.

    Security Best Practice

    When exposing the console to a public network, create a custom administrator and disable or delete the default admin user.

  11. Use cases for r-nacos

    master

    r-nacos is suitable for the following scenarios:

    1. Development and Testing: Replace standard Nacos with r-nacos for near-instant startup times.
    2. Cloud/Personal Resource Deployment: Ideal for environments with limited resources. r-nacos is highly efficient: the package is ~10MB, has no JDK dependency, and typically consumes <0.5% CPU and <5MB RAM during runtime.
    3. Performance and Stability Upgrades: For users of non-customized Nacos services who want to improve overall service performance and stability.