All Products
Search
Document Center

Hologres:Resource consumption and billing for the Serverless Computing feature

Last Updated:Aug 29, 2024

The fees for the Serverless Computing feature of Hologres vary based on the amount of serverless computing resources that are used by big SQL jobs and the usage duration. Big SQL jobs include SQL jobs that generate large CPU or memory overheads. This topic describes how to query the amount of used serverless computing resources and the billing details.

Billing rules

You are charged for the Serverless Computing feature for a SQL job based on CU-H, which is calculated by the number of compute units (CUs) of serverless computing resources that are used by the job multiplied by the usage duration. You are charged on an hourly basis. The system calculates the number of CUs of serverless computing resources that are used by a SQL job in the previous hour and deducts fees every hour. For more information about the unit price of serverless computing resources, see Billing overview.

Important
  • You will be charged for the use of the Serverless Computing feature from July 1, 2024 (UTC+8). You can estimate the cost based on the amount of used serverless computing resources by following the instructions in this topic. You can adjust the resource allocation to jobs to prevent unexpected costs.

  • For more information about the regions and zones in which the Serverless Computing feature is available, see User guide on Serverless Computing.

Only SQL jobs that are executed as expected are billed. Failed SQL jobs are not billed.

Query resource consumption

In Hologres V2.1.18 and later, you can calculate the amount of used serverless computing resources based on the hologres.hg_serverless_computing_query_log view and estimate the costs based on the billing formula. For more information about slow query logs, see Query and analyze slow query logs.

Note
  • For queries that are performed by using serverless computing resources in versions earlier than Hologres V2.2.7, slow query logs record only failed queries and the queries that take more than 100 milliseconds. In Hologres V2.2.7 and later, slow query logs record all queries that are performed by using serverless computing resources.

  • Slow query logs record the resource consumption of each SQL statement. During bill generation, data aggregation and unit conversion may be required. Therefore, the actual resource consumption may be slightly different from the resource consumption in slow query logs.

Permissions

To estimate the consumption of serverless computing resources and the costs based on slow query logs, you must be granted the required permissions. This section describes the required permissions for different operations and how to grant the permissions.

  • Query the total amount of data that is scanned in all databases on an instance

    • Method 1: Assign the superuser role to a user. Sample statement:

      -- Replace Account ID with your Alibaba Cloud account ID. For a RAM user, prefix the account ID with p4_. 
      ALTER USER "Account ID" SUPERUSER;
    • Method 2: Add a user to the pg_read_all_stats user group. Sample statement:

      Note

      Users who are assigned the superuser role and users who belong to the pg_read_all_stats user group have permissions to view the total amount of data that is scanned in all databases. You can add an ordinary user to the user group as a superuser.

      GRANT pg_read_all_stats TO "Account ID";-- Use the standard PostgreSQL authorization model to grant related permissions to the user.
      CALL spm_grant('pg_read_all_stats', 'Account ID');  -- Use the simple permission model (SPM) to grant related permissions to the user.
      CALL slpm_grant('pg_read_all_stats', 'Account ID'); -- Use the schema-level permission model (SLPM) to grant related permissions to the user.
  • Query the amount of data that is scanned in the current database on an instance

    • Use the SPM or SLPM to add a user to the db_admin user group. Users who are assigned the db_admin role have permissions to view the amount of data that is scanned in the current database.

      CALL spm_grant('<db_name>_admin', 'Account ID'); -- Use the SPM to grant related permissions to the user.
      CALL slpm_grant('<db_name>.admin', 'Account ID'); -- Use the SLPM to grant related permissions to the user.
    • Ordinary users can query only the amount of data that is scanned in their queries in the database.

Note

For more information about permissions, see Permission management overview.

Query the resource consumption of a single SQL statement

To query the consumption details of serverless computing resources, execute the following SQL statement:

SELECT
    *,
    queue_time_ms, -- The queuing duration for an SQL statement to wait for serverless computing resources, in milliseconds.
    serverless_allocated_cores, -- The number of CUs of serverless computing resources that are allocated to an SQL statement. 
    serverless_resource_used_time_ms, -- The duration for which an SQL statement occupies serverless computing resources, in milliseconds.
    (serverless_allocated_cores::DECIMAL(38, 4)) * (serverless_resource_used_time_ms::DECIMAL(38, 4)) AS serverless_cums
FROM
    hologres.hg_serverless_computing_query_log;

Query resource consumption in a specific period of time

To query the amount of serverless computing resources that are consumed in a specific period of time by successfully executed tasks, execute the following SQL statement:

SELECT
    (SUM((serverless_allocated_cores::DECIMAL(38, 4)) * (serverless_resource_used_time_ms::DECIMAL(38, 4))) / 1000 / 60 / 60)::bigint AS serverless_cuh
FROM
    hologres.hg_serverless_computing_query_log
WHERE
    status = 'SUCCESS'
    AND serverless_allocated_cores IS NOT NULL
    AND serverless_resource_used_time_ms IS NOT NULL
    AND query_end BETWEEN '2024-05-01 00:00:00' AND '2024-05-31 24:00:00';-- The specified period of time.

Recommended configurations

Hologres provides metrics for the Serverless Computing feature. We recommend that you configure alert rules for the Serverless Computing feature based on your business requirements. This helps prevent unexpected costs.

For example, you can configure the following alert rule for the Serverless Computing Longest Active Query Time metric.

Warn: If the value of this metric is greater than or equal to 3,600,000 milliseconds in 5 consecutive cycles, a warn-level alert is reported. Each cycle lasts for 1 minute.

jiankong.jpg

For more information, see the "Configure alert rules" section in CloudMonitor.

References