Hologres Serverless Computing bills you for resource-intensive SQL jobs, such as those with high CPU or memory overhead, based on the compute resources consumed and the execution time. This topic describes how to view your resource consumption and understand billing details.
Billing
The Serverless Computing feature measures resource usage for each SQL job in Compute Unit·Hour (CU·H). The system calculates this by multiplying the resources consumed by the execution time. Billing is settled hourly. Each hour, the system aggregates the usage from all SQL jobs that ran on Serverless Computing in the previous hour and deducts the corresponding fees. For specific unit prices, see Billing overview.
-
Billing for Serverless Computing officially began on
July 01, 2024Beijing time. Refer to the information below to monitor your Serverless Computing resource consumption and estimate your bill. If necessary, adjust the resource allocation for your jobs to avoid unexpected charges. -
For instances in the China (Beijing), China (Hangzhou), China (Shenzhen), and China (Shanghai) regions, we recommend purchasing a Compute Credit Package to offset costs from the Serverless Computing feature. For more information, see Compute Credit Package.
-
For a list of regions and zones where Serverless Computing is available, see Serverless Computing User Guide.
-
Both
hologres.hg_query_logandhologres.hg_serverless_computing_query_logretain data for the past 30 days.
Only successfully completed SQL jobs are billed. Failed jobs do not incur charges.
Query resource consumption
From Hologres V2.1.18, you can query the hologres.hg_serverless_computing_query_log view to calculate the resource consumption of Serverless Computing tasks and estimate the costs based on the billing formula for Serverless resources. For more information about slow query logs, see View and analyze slow query logs.
-
In versions earlier than
Hologres V2.2.7, the slow query log recorded only successful Serverless Computing tasks with an execution duration longer than100ms and all failed tasks. InHologres V2.2.7and later versions, you can view all Serverless Computing tasks. -
Because billing involves data aggregation and unit conversion, minor discrepancies can occur between the log data and your final bill.
Permissions
To estimate Serverless Computing resource consumption and costs from the slow query log, you need specific permissions. The following sections detail the required permissions and authorization methods.
-
Query the data scan volume for all databases in an instance
-
Option 1: Grant the Superuser permission. The following command grants this permission:
-- Replace "Alibaba Cloud account ID" with the actual username. For a RAM user, prepend the account ID with "p4_". ALTER USER "Alibaba Cloud account ID" SUPERUSER; -
Option 2: Add the user to the pg_read_all_stats user group. Use one of the following commands based on your permission model:
NoteIn addition to the Superuser permission, Hologres allows members of the pg_read_all_stats user group to view the data scan volume for all databases. If a regular user needs to view all logs, they can ask a Superuser to grant them this permission and add them to the group.
GRANT pg_read_all_stats TO "Alibaba Cloud account ID"; -- For the expert permission model CALL spm_grant('pg_read_all_stats', 'Alibaba Cloud account ID'); -- For the simple permission model (SPM) CALL slpm_grant('pg_read_all_stats', 'Alibaba Cloud account ID'); -- For the schema-level simple permission model (SLPM)
-
-
View the data scan volume for the current database
-
Enable the simple permission model (SPM) or the schema-level simple permission model (SLPM) and add the user to the db_admin role. The db_admin role can view the data scan volume for the current database. Use one of the following commands to grant this role.
CALL spm_grant('<db_name>_admin', 'Alibaba Cloud account ID'); -- For SPM CALL slpm_grant('<db_name>.admin', 'Alibaba Cloud account ID'); -- For SLPM -
A regular user can query the data scan volume for queries that they have executed in the current database under their own account.
-
For more information about permission operations, see Permission Management Overview.
Query consumption for a single SQL
Use the following SQL statement to query the detailed resource consumption of a Serverless Computing job.
SELECT
*,
queue_time_ms, -- The time a SQL query spends waiting in the Serverless Computing queue, in milliseconds (ms).
serverless_allocated_cores, -- The number of CUs actually allocated to the current SQL query by Serverless Computing.
serverless_resource_used_time_ms, -- The duration that the SQL query actually occupies Serverless Computing resources, in milliseconds (ms).
(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 consumption over a time range
Use the following SQL statement to query the total resource consumption of successful Serverless Computing jobs within a specified time range.
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+08'::timestamptz AND '2024-05-31 24:00:00+08'::timestamptz;-- Specify the time range.
Estimate resource consumption
If you have not yet enabled Serverless Computing but want to run certain SQL queries by using serverless resources, you can first execute them on your Hologres instance. The hologres.hg_query_log system table contains the cpu_time_ms field, which you can use to find the CPU time consumed by the SQL job. Then, you can use the formula cpu_time_ms / 1000 / 60 / 60 to roughly estimate the consumption if the same query were run with serverless resources. The SQL command to query the cpu_time_ms information is as follows:
SELECT cpu_time_ms FROM hologres.hg_query_log WHERE query_id = 'xxx';
Instance resources can be affected by other workloads, whereas serverless resources are isolated. Additionally, their resource capacities may differ. Therefore, this method cannot provide a precise estimate of serverless resource consumption. We recommend that you select a few key SQL jobs and follow the Serverless Computing User Guide to test them directly with serverless resources. This allows you to measure actual resource consumption without affecting other jobs on your instance.
Monitor costs and configure alerts
Set a daily usage limit
Starting with Hologres V3.1.5, you can use SQL to set a daily limit on Serverless Computing resource usage. Only a Superuser can set this limit.
-- Set a limit for a database.
ALTER DATABASE <db_name> SET hg_serverless_computing_daily_max_cuh_usage_threshold = <value>;
-- Set a limit for a user.
ALTER USER <user_name> SET hg_serverless_computing_daily_max_cuh_usage_threshold = <value>;
-
Limit details
-
The default value is -1, which means no limit is set.
-
The unit is CU·H.
-
Hologres aggregates and updates the total Serverless Computing resource usage for the current instance every 10 minutes. Therefore, there may be a delay of up to 10 minutes in enforcing the limit.
-
Before executing a SQL query, Hologres compares the total serverless resources used today by the instance with the serverless resource limit for the current user or database. If the limit is reached, the query automatically falls back to using the instance's compute resources. If the limit has not been reached, the query runs by using serverless resources as normal.
-
Hologres calculates the daily usage of Serverless Computing resources based on the natural day in the default time zone of the current database. You can run the following commands in the same session to query the default time zone of the current database.
-- Reset the time zone to avoid influence from the client or user's default time zone. RESET timezone; -- Query the default time zone of the current database. SHOW timezone;
-
-
Recommendations
-
If you are a long-term user of the Hologres Serverless Computing feature, you can determine an appropriate daily usage limit by querying your resource consumption over a specific time range.
-
If you have not used the Hologres Serverless Computing feature before, we recommend that you first use the feature until your workload stabilizes. Then, based on your usage patterns, decide whether to set a daily usage limit and determine an appropriate value.
-
If you do not want SQL queries to fall back to instance compute resources when the Serverless Computing limit is reached, you can run the following command to make them fail immediately. This parameter can be set only by a Superuser.
-- Set the parameter at the database level.
ALTER DATABASE <db_name> SET hg_serverless_computing_enable_fallback_when_exceed_cuh_threshold = false;
-- Set the parameter at the user level.
ALTER USER <user_name> SET hg_serverless_computing_enable_fallback_when_exceed_cuh_threshold = false;
-
The default value is
true. When the limit is exceeded, SQL queries automatically fall back to using instance resources. -
This parameter can be set to
false. If the limit is exceeded, the SQL query fails immediately and returns the following error:serverless computing is not available due to exceeding cuh usage threshold, please adjust the threshold or trun off serverless computing for current query.
Cost analysis
You can use the module in Expenses and Costs to monitor and analyze the costs for Hologres Serverless Computing compute resources.
-
Log on to Expenses and Costs. In the left-side navigation pane, click .
-
On the Cost Analysis page, in the section on the right, select Billing Item. Then, select a Cost Type and Time Granularity based on your needs.
-
In the Filter Conditions area on the right side of the Cost Analysis page, set Billing Item to Serverless Computing compute resource, Hologres Dedicated Instance (Pay-As-You-Go) , and click Apply Filter Conditions. You can then view the Serverless Computing costs for the specified time range.
For more information, see Cost Analysis.
Spending alerts
You can use Alibaba Cloud Expenses and Costs to manage budgets and set alerts for pay-as-you-go spending on specific products in certain regions. For more information, see Expense Alerts.
Alerts for single SQL duration
Hologres supports runtime metrics for Serverless Computing. We recommend creating alert rules based on your business use cases to avoid unexpected costs.
For example, for the metric Longest duration among running Serverless Computing queries, we recommend the following alert rule:
Warn: "The 'Longest duration among running Serverless Computing queries' is greater than or equal to 3,600,000 milliseconds for 5 consecutive periods (1 period = 1 minute)."
For more information, see Monitoring and alerting best practices.
Related topics
-
For an overview of the Serverless Computing feature, see Serverless Computing.
-
For instructions on how to use the Serverless Computing feature, see Serverless Computing User Guide.