Deploy a PAI-Rec engine service

Updated at:

This topic describes how to deploy an engine service to PAI-EAS by using PAI-Rec.

Create an engine configuration list

Before you start the PAI-Rec engine, you must create and publish an engine configuration list to the staging and production environments. The engine initializes based on the settings in the list. If you later modify the configuration, you can publish the updated version, and the engine will apply the changes through hot reloading without a service restart. Note that hot reloading does not apply to all changes. For example, changes to data source parameters, such as changing the database for a Hologres data source, are not supported. Additionally, if you delete a scene's configuration while requests are still using that scene, requests may continue to use the deleted configuration.

  1. Log on to the PAI-Rec Management Console. In the left-side navigation pane, choose Engine Service Management > Engine Configuration.

  2. In the Staging environment, click Create Configuration. The system provides a default configuration you can use to create the list directly.

  3. Click Clone to create a configuration list for the production environment by copying a configuration from the staging environment.

    In the Clone Configuration List dialog box, enter a Clone Configuration List Name and select the version to clone from the Clone Configuration List Version drop-down list.

  4. In the Production environment, click Details next to the target configuration list to publish it.

Create a service

  1. Log on to the PAI-Rec Management Console. In the left-side navigation pane, choose Engine Service Management > Service Management.

  2. Click Create Service and configure the following parameters.

    1. Basic configuration

      Parameter

      Description

      Service Name

      The name of the service deployed to PAI-EAS.

      Service Description

      A description of the service.

      Region

      The region where the service is deployed in PAI-EAS.

      Image Name

      Select Official Image if you do not need to write custom code. If you require custom code, select Custom Image and refer to Quickstart: Create a project to package your image.

      Image Secret

      The image key PAI-EAS uses to pull the image.

      Recommendation Engine Configurations

      The name of the engine configuration used by the engine service. The engine configurations for the staging and production environments must be published first.

    2. EAS configuration

      1. Configure EAS parameters.

        Parameter

        Description

        EAS Resource Group

        If you do not have a private resource group, you can use the Public Resource Group.

        EAS Configuration File

        Includes configurations for the Staging Environment Configuration and Production Environment Configuration. These are used to create staging and production services in PAI-EAS.

      2. On the Staging Environment Configuration tab, click Create. PAI-Rec automatically creates the service in PAI-EAS based on your settings.

        The page prompts you to ensure that the PaiRecDataManagementAccess policy is granted to the AliyunPAIRecEASRole role. After you confirm the configuration, click Create.

      3. After selecting the corresponding workspace, click Enter EAS. On the Elastic Algorithm Service (EAS) page, find the service you just deployed. When the service status changes to Running, the staging service is successfully deployed. You can click the service name to view service logs and other information.

      4. The procedure for deploying a production service is the same as that for a staging service. If a staging or production service deployment fails, first go to the RAM console to check whether the AliyunPAIRecEASRole role has the PaiRecDataManagementAccess policy attached. If the permission is correctly configured, check the service logs to identify the specific error. For example, if you encounter a permission-related error, see Q: Permission denied during engine startup (Message: ram permission err: permission denied, accessDeniedDetail: {"AuthAction":"pairec:ListScenes",xxxx}) to resolve the issue.

    3. Staging/production release

      If you deploy the service by using an official image, you can skip this step and create the service directly.

Test the service

After deploying the service, test it. For more information, see API reference.

Test in the EAS console

  1. Log on to the PAI-EAS console, click the service name, and go to the Debug tab. Test the service by selecting POST as the HTTP method. For the request URL, append /api/rec/feed to your service endpoint. An example of a complete URL is http://17307601***.com/api/predict/pairec_config_test/api/rec/feed. For the Body, select the raw format and enter the request body, for example: {"scene_id":"home_feed","size":10,"uid":"76295990"}. After you send the request, the Response area should return a 200 status code and a JSON response containing code:200, msg:success, an experiment_id, and 10 recommended items. Each item includes an item_id, a score, and a retrieve_id.

  2. After the service processes a request, use the request_id from the response to view detailed logs.

    On the Log tab, paste the request_id value into the Keyword search box to filter the logs. The log details show the complete processing path for the recommendation request: controller begin → feed (including scene parameters like scene_name and exp_room_id) → MockRecall → recall → Filter → LoadFeatures → rank → controller end. The time taken (cost) for each module is recorded in milliseconds, which helps you identify performance bottlenecks.

Test in the PAI-Rec console

Log on to the PAI-Rec Management Console. In the left-side navigation pane, choose Troubleshooting Tool > Recommendation Result Diagnostics to run tests based on your service, environment, and interface.

On the page, configure the Associated PAI-Rec Service, Environment Settings (for example, select Production), Routing Information, and Item Table. Edit the request JSON in the Request Data area, enable debug mode if needed, and then click Diagnose to view the recommendation results.

Engine configuration

The API response shows that for the input parameter size, an equal number of items are returned, and the recall source name is mock_recall.

In RecallConfs, a mock recall mock_recall is defined, and in SceneConfs, it is referenced by the home_feed scene.

For details about the engine configuration, see Engine configuration.

   "RecallConfs": [
        {
            "Name": "mock_recall",
            "RecallType": "MockRecall",
            "RecallCount": 200
        }
    ],
    "SceneConfs": {
        "home_feed": {
            "default": {
                "RecallNames": [
                    "mock_recall"
                ]
            }
        }
    }
Warning

When the service goes live, you must remove mock_recall from RecallNames.

Engine configuration hot reloading

After the service is deployed, you can adjust the Engine Configuration based on your actual requirements. For example, you can adjust the recall count of mock_recall from 200 to 500.

  1. Log on to the PAI-Rec Management Console. In the left-side navigation pane, choose Engine Service Management > Engine Configuration.

  2. On the Production tab, click View next to the target engine.

    On the engine configuration page, find the target configuration list and click Details in the Actions column to view the configuration details.

  3. Click Create Change Ticket. You can create new content based on the published configuration or make multiple edits to an unpublished configuration.

    In the Create Configuration List Content panel, you can choose to Start editing from the configuration content of the currently published version or Start editing from a configuration template. In the JSON editor below, modify the engine configuration parameters. For example, set RecallCount to 500 in RecallConfs.

  4. After you finish editing, click Release.

  5. After the configuration is published, the PAI-Rec engine service reads the new settings and applies them through hot reloading, without requiring a service restart.

    Search for reload on the EAS service log page to verify that the changes were loaded. A log entry that contains the keyword reload and the corresponding configuration version number, such as 20240909183616, indicates that the engine configuration hot reloading was successful.

    The loaded version corresponds to the published version.

    In the version list for the engine configuration, the status of the published version (for example, 20240909183616) appears as Published. The Edit and Publish operations are grayed out, and you can only View Configuration.

    If you test the service again using the method described earlier, you will find that the recall count has changed.

    On the EAS service log page, filter by requestId to view the full request path. The mock_recall.go log shows module=MockRecall count=500 cost=1, which indicates that the recall count for the MockRecall module has changed to 500. The total request latency is cost=5 ms.