Updated on 2024-06-12 GMT+08:00

Accessing a Real-Time Service (VPC High-Speed Channel)

Context

When accessing a real-time service, you may require:

  • High throughput and low latency
  • TCP or RPC requests

To meet these requirements, ModelArts enables high-speed access through VPC peering.

In high-speed access through VPC peering, your service requests are directly sent to instances through VPC peering but not through the inference platform. This accelerates service access.

The following functions that are available through the inference platform will be unavailable if you use high-speed access:

  • Authentication
  • Traffic distribution by configuration
  • Load balancing
  • Alarm, monitoring, and statistics
Figure 1 High-speed access through VPC peering

Preparations

Deploy a real-time service in a dedicated resource pool and ensure the service is running.

  • For details about how to deploy services in new-version dedicated resource pools, see Comprehensive Upgrades to ModelArts Resource Pool Management Functions.
  • Only the services deployed in a dedicated resource pool support high-speed access through VPC peering.
  • High-speed access through VPC peering is available only for real-time services.
  • Due to traffic control, the number of calls of each tenant account cannot exceed 2000 per minute, and that of each IAM user account cannot exceed 20 per minute.
  • High-speed access through VPC peering is available only for the services deployed using the AI applications imported from custom images.

Procedure

To enable high-speed access to a real-time service through VPC peering, perform the following operations:

  1. Interconnect the dedicated resource pool to the VPC.
  2. Create an ECS in the VPC.
  3. Obtain the IP address and port number of the service.
  4. Access the service through the IP address and port number.
  1. Interconnect the dedicated resource pool to the VPC.

    Log in to the ModelArts management console, choose Dedicated Resource Pools > Elastic Cluster, locate the dedicated resource pool used for service deployment, and click its name/ID to go to the resource pool details page. Obtain the network configuration. Switch back to the dedicated resource pool list, click the Network tab, locate the network associated with the dedicated resource pool, and interconnect it with the VPC. After the VPC is accessed, the VPC will be displayed on the network list and resource pool details pages. Click the VPC to go to the details page.

    Figure 2 Locating the target dedicated resource pool
    Figure 3 Obtaining the network configuration
    Figure 4 Interconnecting the VPC

  2. Create an ECS in the VPC.

    Log in to the ECS management console and click Buy ECS in the upper right corner. On the Buy ECS page, configure basic settings and click Next: Configure Network. On the Configure Network page, select the VPC connected in 1, configure other parameters, confirm the settings, and click Submit. When the ECS status changes to Running, the ECS has been created. Click its name/ID to go to the server details page and view the VPC configuration.

    Figure 5 Purchasing an ECS

  3. Obtain the IP address and port number of the service.

    GUI software, for example, Postman can be used to obtain the IP address and port number. Alternatively, log in to the ECS, create a Python environment, and execute code to obtain the service IP address and port number.

    API:

    GET /v1/{project_id}/services/{service_id}/predict/endpoints?type=host_endpoints

    For details about how to obtain a service endpoint, see "Before You Start" > "Endpoints" in ModelArts API Reference.

    • Obtain the IP address and port number using GUI software.
      Figure 6 Example response
    • Obtain the IP address and port number using Python.

      The Python code is as follows (mandatory parameters must be configured):

      def get_app_info(project_id, service_id):
      list_host_endpoints_url = "{}/v1/{}/services/{}/predict/endpoints?type=host_endpoints"
      url = list_host_endpoints_url.format(REGION_ENDPOINT, project_id, service_id)
      headers = {'X-Auth-Token': X_Auth_Token}
      response = requests.get(url, headers=headers)
      print(response.content)

  4. Access the service through the IP address and port number.

    Log in to the ECS and access the real-time service either by running Linux commands or by creating a Python environment and executing Python code. Obtain the values of schema, ip, and port from 3.
    • Run the following command to access the real-time service:
      curl --location --request POST 'http://192.168.205.58:31997' \
      --header 'Content-Type:  application/json' \
      --data-raw '{"a":"a"}'
      Figure 7 Accessing a real-time service
    • Create a Python environment and execute Python code to access the real-time service.
      def vpc_infer(schema, ip, port, body):
      infer_url = "{}://{}:{}"
      url = infer_url.format(schema, ip, port)
      response = requests.post(url, data=body)
      print(response.content)