Help Center/ AI DataLake/ Getting Started/ Data Processing Using RayCluster
Updated on 2026-11-06 GMT+08:00

Data Processing Using RayCluster

Scenarios

AI DataLake is a fully managed lakehouse analytics service from Huawei Cloud. It provides end-to-end data management and analytics, supporting multi-engine job development to meet diverse big data needs.

This section demonstrates how to analyze data using AI DataLake by creating a compute resource pool, configuring a RayCluster endpoint, connecting a data source, and submitting a job via an API.

Procedure

Before using the following sample, complete necessary operations. For details, see Preparations.

  1. Planning and Creating an OBS Bucket: Create an OBS bucket to store job scripts.
  2. Creating a Workspace: Create a workspace.
  3. Creating a Compute Resource Pool: Create a compute resource for running jobs.
  4. Creating a Ray Endpoint for Running Jobs: Create a Ray endpoint and associate it with a compute resource pool to obtain the resources required for executing jobs.
  5. Submitting a Job via an API: Use an API to encapsulate REST requests and submit AI DataLake jobs to the Ray endpoint for execution. This section uses a simple text-processing AI DataLake job as an example.

Preparations

  • You have registered an account and completed real-name authentication. The account balance is sufficient, and the account is not frozen.
  • You have enabled AI DataLake and obtained the required permissions for the cloud resources.
  • You have obtained OBS permissions and configured the required agency.
  • You have built an image, uploaded it to SWR, and registered it with AI DataLake.
  • You have obtained an IAM token. For details, see Obtaining an IAM User Token.

Step 1: Plan and Create an OBS Bucket

AI DataLake Ray uses OBS to submit jobs and store data. You must create a bucket and a folder on the OBS console, and then import sample data or job scripts.

  1. Log in to the Huawei Cloud OBS console.
  2. Choose Buckets and click Create Bucket. On the page that appears, configure the parameters and click Create Now.
    • Bucket Name: Enter a name for the bucket as required.
    • Configure other parameters based on your business requirements.
  3. In the bucket list, click the name of the new bucket.
  4. Compress the job script into a .zip file, click the Objects tab, and then click Upload Object to upload the file to the created OBS bucket.

    For example, upload the text-processing script create_csv.py. Its content is shown below:

    import csv
    
    # Prepare data.
    data = [
        ['Name', 'Age', 'City'],
        ['Alice', 30, 'New York'],
        ['Bob', 25, 'Los Angeles'],
        ['Charlie', 35, 'Chicago']
    ]
    
    # Open the file and create a CSV writer.
    with open('output.csv', 'w', newline='') as file:
        writer = csv.writer(file)
        writer.writerows(data)
    
    # Open the file and create a CSV reader.
    with open('output.csv', 'r', newline='') as file:
        reader = csv.reader(file)
    
        # Skip the table header.
        next(reader)
    
        # Read and print the data from the "Name" column.
        for row in reader:
            print(row[0])
    # Before the job completes, clear any temporary files generated during execution to free up temporary storage space. Replace temp_path with the actual temporary file directory (for example, /home/service/works).
    if os.path.exists(temp_path):
        if os.path.isdir(temp_path):
            shutil.rmtree(temp_path)
        else:
            os.remove(temp_path)

Step 2: Create a Workspace

  1. Log in to the AI DataLake console.
  2. In the left navigation pane, click the workspace area.
  3. Select Create Workspace from the drop-down list.
  4. Set the following workspace parameters.
    Table 1 Basic workspace information

    Category

    Parameter

    Example Value

    Description

    Basic Information

    Workspace Name

    workspace_raytest

    The name of the workspace to create. Workspace names must be unique within the same account.

    • The name can contain only letters, digits, hyphens (-), and underscores (_).
    • The name must be 4 to 32 characters long.

    Description

    Smart driving data analytics

    A brief description of the workspace. It cannot exceed 255 characters.

    Enterprise Project

    default

    If the workspace you are creating belongs to an enterprise project, select that enterprise project.

    EPS provides enterprise projects that group cloud resources by project to manage resources and users within specific projects.

    For details about how to configure enterprise projects, see Enterprise Management User Guide.

    NOTE:

    This parameter appears only for users with the EPS service enabled.

    Multimodal Data Management

    LakeFormation Instance

    lakeformation_for_raytest

    Select the LakeFormation instance associated with the current workspace. Each workspace must be associated with one LakeFormation instance. You cannot change this instance after the workspace is created.

    • Select a LakeFormation instance to centrally manage metadata and control data access.
    • If no instance is available, first create a LakeFormation instance.
  5. Confirm the settings and click Create Now to create the workspace.

    After the workspace is created, you can view it in the workspace management list.

Step 3: Create a Compute Resource Pool

  1. On the AI DataLake console, use the drop-down menu in the upper left corner to switch to the target workspace.
  2. In the left navigation pane, choose Resource Management > Compute Resource Pools, and then click Buy in the upper right corner to open the purchase page.
  3. On the Buy Compute Resource Pool page, set the parameters.
    Table 2 Parameters for purchasing a compute resource pool

    Parameter

    Example Value

    Description

    Billing Mode

    Pay-per-use

    • Yearly/Monthly: A prepaid billing mode where you pay in advance for a specified duration. Resources are dedicated to your account during the subscription period and remain allocated even when no jobs are running (idle). This mode ensures optimal user experience and is more cost-effective than pay-per-use billing for long-term workloads.

      This cost-effective mode is ideal for predictable workloads, such as stable production environments that have completed development.

    • Pay-per-use: You are billed based on the actual runtime (billed by the second and settled hourly). Resources are dedicated to your account. You can use or release them at any time.

    Resource Pool Name

    resource-pool-for-raytest

    The name of the compute resource pool.

    • The name can contain only lowercase letters, digits, and hyphens (-), and must start with a letter and end with a letter or digit.
    • The name can contain a maximum of 63 characters.

    CPU Resources

    In this example, eight general-computing standard instances are configured.

    CPUs are general-purpose compute resources suitable for a variety of tasks.

    • CPU resources are versatile and suitable for various computing tasks. CPUs are more cost-effective than GPUs or NPUs and excel at processing sequential tasks.
    • CPU resources are suitable for ETL (extract, transform, and load) workflows, lightweight computing scenarios (such as small-scale data processing and script execution), and log analysis scenarios (such as log collection, parsing, and statistical analysis).
    • For details about CPU specifications, see Product Specifications.

    GPU Resources

    In this example, no GPU instances are purchased.

    GPUs are suitable for graphics rendering and large-scale parallel computing, and are ideal for deep learning training and scientific computing. GPUs have hundreds or thousands of computing cores and can process a large number of simple tasks simultaneously.

    • GPU resources support parallel computing and are suitable for batch processing jobs. Thousands of cores can execute tasks simultaneously, resulting in high processing efficiency. GPUs are ideal for deep learning, neural networks, and AI workloads.
    • GPU resources are suitable for deep learning (such as neural network training and model optimization), image processing (such as image recognition and object detection), video processing (such as video analysis, transcoding, and rendering), and other scientific computing workloads.
    • For details about GPU specifications, see Product Specifications.

    NPU Resources

    In this example, no NPU instances are purchased.

    NPUs are suitable for AI workloads. NPU resources use an optimized architecture and instruction set to accelerate AI inference tasks, delivering high energy efficiency.

    • NPU resources are dedicated to AI workloads and feature high performance, low latency, and low inference costs.
    • NPU resources are suitable for AI workloads, image recognition, and recommendation systems.
    • For details about NPU specifications, see Product Specifications.

    AI DataLake Network

    Configure as required.

    Select the network to which the AI DataLake resource pool belongs. The network is built on a VPC. If no network is available, click Create Network to create one.

    Each workspace supports only one network.

  4. After configuring the parameters, click Buy Now and confirm the settings on the displayed page.
  5. Click Submit. Wait until the resource pool status changes to Available, indicating that the resource pool has been successfully created.

Step 4: Create a Ray Endpoint for Running Jobs

  1. On the AI DataLake console, use the drop-down menu in the upper left corner to switch to the target workspace.
  2. In the left navigation pane, choose Engine Endpoints > Ray. The Ray engine endpoint list appears.
  3. Click Create Endpoint in the upper right corner of the page, configure the following parameters, and click Create Now.
    Table 3 Parameters for creating a Ray engine endpoint

    Parameter

    Example Value

    Description

    Endpoint Type

    RayCluster

    Select an endpoint type.

    RayCluster: Persistent mode. This mode supports multiple Ray job submissions.

    Endpoint Name

    ray-test

    Enter an endpoint name. It is a unique endpoint identifier. This name cannot match an existing endpoint and cannot be changed after creation.

    The name can contain only lowercase letters, digits, and hyphens (-), and must start with a letter and end with a letter or digit.

    The name can contain a maximum of 63 characters.

    Endpoint Display Name

    Dedicated Ray endpoint for development team-01

    Enter an endpoint display name. This name can be changed after creation and appears on the console to help users identify the endpoint.

    • The name can contain only letters, digits, and hyphens (-).
    • The name can contain a maximum of 63 characters.

    Resource Allocation

    Reserved

    Select a resource allocation mode.

    Reserved: Dedicated compute resources are reserved to ensure stable performance for your services and offer the best unit price.

    Compute Resource Pool

    resource-pool-for-raytest

    Select an existing resource pool from the drop-down list.

    Cluster Settings

    • Head:64vCPU,128GiB
    • Workergroups:64vCPU,128GiB

    Configure the head node and worker group specifications for the Ray cluster. You can create multiple worker groups based on your workload requirements.

    Image Settings

    Custom Ray image

    Select the cluster image version.

    Built-in Images: Standard images provided by AI DataLake.

    Custom Images: SWR images registered by the user.

    Storage Settings

    • Ephemeral Storage: sfs-turbo-01
    • Storage Path: /
    • Mount Point: /home/service/works

    Based on shared storage (SFS Turbo), the mount point standardizes the access path inside the container, while the storage path specifies independent physical subdirectories for the head and worker nodes. This implements cross-node data sharing and prevents data write conflicts across multiple nodes.

  4. Once the endpoint is created, you can view its details in the endpoint list. After the status changes to Running, you can submit jobs to the endpoint.

Step 5: Submit a Job via an API

This example uses the requests library to demonstrate how to run a simple script (for example, request.py) to submit a text-processing job to a specified Ray cluster.

Example request script:

import requests
import json
import urllib3
import time

# Suppress SSL warnings.
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

# Common configurations
TOKEN = "XXX"  # IAM token
WORKSPACE_ID = "3fa4b5a6-9208-4254-b823-119aa29c****"  # Workspace ID
HEADERS = {"X-Auth-Token": TOKEN, "Content-Type": "application/json"}
ENDPOINT = "https://fabric.cn-southwest-2.myhuaweicloud.com" # In a real-world scenario, the ENDPOINT is the value of the corresponding region endpoint. In this example, the endpoint for the CN Southwest-Guiyang1 region is used.
# URL for job submission and execution
URL_SUBMIT_RUN = f"{ENDPOINT}/v2/workspaces/{WORKSPACE_ID}/ray-jobs"

def submit_run():
    payload = {
        "name": "ray-test",
        "description": "description",
        "endpoint_name": "ray-test",   #Replace this value with the RayCluster endpoint name.
        "config": {
            "entrypoint": "python3 create_csv.py",  #When a job runs, its script .zip file automatically decompresses. If decompression produces only one top-level folder, that folder is automatically removed. Therefore, enter only the script file name here, without including the parent directory.
            "runtime_env": {
                "working_dir": "obs://ray-shared-csc/ray-zy/create_csv.zip", #Replace this value with the OBS path where the job script is stored. The file must be a .zip file.
                "py_modules": [
                    "string"
                ],
                "pip": [
                    "numpy==1.16.1"  # Optional. This specifies a pip dependency library. If no pip dependency is required, leave this parameter blank.
                ],
                "env_vars": {
                    "additionalProp1": "value1",  # Optional. This specifies an environment variable. If no environment variable is required, leave this parameter blank.
                    "additionalProp2": "value2",
                    "additionalProp3": "value3"
                }
            }
        }
    }

    try:
        response = requests.post(
            URL_SUBMIT_RUN, headers=HEADERS, json=payload, verify=False
        )
        if response.status_code in [200, 201, 202]:
            print(
                f"Job submitted successfully. Response code: {response.status_code}. Response content: {response.text}"
            )
        else:
            print(f"Job submission failed. (Code: {response.status_code})")
            print(response.text)
    except Exception as e:
        print(f"Request failed: {e}")

if __name__ == "__main__":
    submit_run()
After submitting a job, you can view the job by performing the following operations:
  1. In the left navigation pane of the AI DataLake console, choose Job Development > Job Run History.
  2. On the page that appears, click the Ray tab to view the job information.