Data Processing Using RayJob
Scenarios
This section demonstrates how to analyze data using AI DataLake by creating a compute resource pool, creating a RayJob 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.
- Planning and Creating an OBS Bucket: Create an OBS bucket to store job scripts.
- Creating a Workspace: Create a workspace and associate it with a LakeFormation instance.
- Creating a Compute Resource Pool: Create a compute resource for running jobs.
- Creating a RayJob Endpoint for Running Jobs: Create a RayJob endpoint and associate it with a compute resource pool (except in on-demand resource allocation mode) to obtain the resources required to run jobs.
- Submitting a Job via an API: Use an API to submit a job to the RayJob endpoint for execution. This example demonstrates how to submit a simple text-processing AI DataLake job.
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 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.
- Log in to the Huawei Cloud OBS console.
- 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.
- In the bucket list, click the name of the new bucket.
- 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
- Log in to the AI DataLake console.
- In the left navigation pane, click the workspace area.
- Select Create Workspace from the drop-down list.
- 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.
- 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
- On the AI DataLake console, use the drop-down menu in the upper left corner to switch to the target workspace.
- 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.
- 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.
- 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.
- After configuring the parameters, click Buy Now and confirm the settings on the displayed page.
- Click Submit. Wait until the resource pool status changes to Available, indicating that the resource pool has been successfully created.
Step 4: Create a RayJob Endpoint for Running Jobs
- On the AI DataLake console, use the drop-down menu in the upper left corner to switch to the target workspace.
- In the left navigation pane, choose Engine Endpoints > Ray. The Ray engine endpoint list appears.
- Click Create Endpoint in the upper right corner of the page, configure the following parameters, and click Create Now.
- Configure basic information.
Table 3 Basic information Parameter
Example Value
Description
Endpoint Type
RayJob
Set the endpoint type to RayJob.
RayJob endpoints provide on-demand task execution units that are destroyed after use. Resources are automatically released once tasks are completed to reduce costs. However, because the cluster must start up each time a task is submitted, you may experience a slight startup delay. This type of endpoint is ideal for one-off tasks where resources are automatically released upon completion.
Endpoint Name
ray-job-owin
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
ray-job-owin
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.
- Configure resource settings.
Table 4 Resource configuration Parameter
Example Value
Description
Resource Allocation
Reserved
Select a resource allocation mode.
- Reserved: Uses reserved resource pools to provide exclusive resources. This mode is ideal for stable, continuous workloads, such as production projects and critical tasks.
- Hybrid: Provides baseline stability and automatic scaling. Reserved resources are used first, and auto scaling is triggered automatically during peak hours. This mode is best for workloads with predictable fluctuations.
- On-demand: Charges you based on the actual time taken to execute each task. No costs are incurred when no tasks are running. This mode is well-suited for short-term or ad-hoc tasks, including development, testing, and temporary projects.
Compute Resource Pool
resource-pool-for-raytest
Select an existing resource pool from the drop-down list. If no resource pool is available in the drop-down list, click Buy Compute Resource to purchase one. For details, see Buying a Reserved Resource Pool.
- Configure specifications.
Table 5 Specification configuration Parameter
Description
Specifications
Select a resource flavor and set the quantity.
- Resource Flavor: Select a flavor from the drop-down list. CPU, GPU, and NPU resources are supported.
- Resource Quota (Min-Max): Set the minimum and maximum resources that the resource pool allocates to this endpoint. The minimum value is grayed out by default and cannot be changed. The minimum value must be greater than 0 and less than or equal to the maximum value.
You can click Add Flavor to configure multiple flavors, or click Delete to remove one. A maximum of 10 flavors can be added. You must keep at least one flavor configuration.
NOTE:- This parameter applies only when the resource allocation mode is set to Reserved or Hybrid.
- After the specifications are configured, you can view the resource specifications, as well as the minimum and maximum resource quantities, in the Resource Quota area on the right side of the page.
- Configure an agency.
Table 6 Agency settings Parameter
Example Value
Description
Agency Settings
ai_datalake_admin_trust
Agency-assigned endpoint permissions are automatically converted to credentials and updated in the Ray cluster during job runtime. You can use these credentials in the Ray cluster to access the required services.
You must enable Agency Settings, and then select an agency name. If no agency is available, click Create Agency. For details, see Creating a Custom Agency.
- Configure basic information.
- 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 demonstrates how to use a tool, such as Postman, to call the job submission API and submit a simple text-processing RayJob.
- Check the image version and ID.
- On the AI DataLake console, choose Image Management in the left navigation pane.
- On the Built-in Images or Custom Images tab, click the image name.
- Verify the version and ID of the built-in or custom image.
- Check the built-in image version and ID: Click the Versions tab, and view the image version and ID in the Image Version/ID column.
- Check the custom image version and ID: View the image version and ID in the Image Version/ID column.
If no custom image is available, register one manually. For details, see Registering a Custom Image.
- Use a tool such as Postman to call the job submission API and submit a job.
- For details about calling APIs, see Calling APIs.
- For details about the parameters of the job submission API, see Running a Job.
The following is an example API request for submitting a job:
POST https://{endpoint}/v2/workspaces/{workspace_id}/ray-jobs { "name": "rayjob0615-4", #Job name "description": "description", #Job description "config": { "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. }, "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. "image": { "id": "dd877a59-5cbd-44c5-b8a7-dc464cca****", #Replace this value with your actual image ID. "image_version": "01ae8ee6-af8a-48a8-895b-8d4a70bf****" #Replace this value with your actual image version. }, "resource_config": { "head_resource_spec": { "cpu": 1020, "memory": 2048, "worker_gpu_amount": 0, "worker_npu_amount": 0 }, "worker_resource_spec": [ { "cpu": 1000, "memory": 2049, "worker_gpu_amount": 0, "worker_npu_amount": 0, "worker_replicas": 1, "enable_autoscaling": true, "worker_min_replicas": 1, "worker_max_replicas": 1 } ] }, "rayjob_strategy": { "queued_timeout": 100000, "running_timeout": 100000 } }, "endpoint_name": "ray-job-owin" #Replace this value with your actual endpoint name. } - View the job.
- In the left navigation pane of the AI DataLake console, choose Job Development > Job Run History.
- On the page that appears, click the Ray tab to view the job information.
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot