SAP Home Learn Build Integrate Model Operate Extend with AI ConnectTutorial navigator Knowledge Graph API Devtoberfest Developer Advocates App Space

Manage my Account SAP Devs YouTube ↗ Learnings ↗ Community ↗ Provide Feedback ↗
Logout
โคข Open full site

Use an Elastic Compute Node (ECN) for Scheduled Workloads

Learn about Elastic Compute Nodes (ECNs) and how they can be used to address known peaks in scheduled workloads.

Overview

🎓 intermediate 45 min. SAP HANA CloudIntermediateSAP HANA Cloud SAP HANA Database

You will learn

  • โœ”How to create and delete an ECN
  • โœ”How to create a workload class and map its workload to an ECN
  • โœ”How to view additional details about ECNs An Elastic Compute Node (ECN) can be added when it is known that additional queries will be run that take significant CPU or memory resources such as at the end of the month or quarter. Once the queries complete, the node can be removed. ECNs incur additional costs while running but can improve performance or could lower the total cost of ownership if their usage can reduce the instance size by covering known peak loads. In the screenshot below, if the timing of the darker blue peaks are known and are read only, an ECN node can be started and the workloads directed to the ECN enabling the overall size of the SAP HANA instance to be reduced. The SAP HANA Cloud Capacity Unit Estimator can be used to estimate the additional cost of adding ECNs. ECNs are not available in trial or free tier. Further details on Elastic Compute Nodes can be also found at Harnessing Dynamic Elasticity (Elastic Compute Node) for Smarter Scaling in SAP HANA Cloud.
    workload
    workload
    ECNs can be used to address compute intensive OLAP or read-only queries and as such, only temporary tables or replica tables can be stored on ECN instances. Queries can be routed to ECN nodes using client-side statement routing or workload classes. The following steps attempt to demonstrate an example of adding an ECN to cover known peaks in workload.

Prerequisites

Prerequisites

  • An SAP BTP account
  • A non trial/free tier SAP HANA Cloud instance

Steps

Step 1 Identify tasks to be run on an Elastic Compute Node (ECN)
โ€”

  1. Read only CPU or memory intensive tasks that occur at a set frequency are suitable candidates to consider redirecting to an ECN. The CPU and memory used by your instance can be viewed in the usage monitor app in SAP HANA Cloud Central as shown below.

    instance details
    instance details

    Click on the memory, compute, network, or storage cards to open the Usage Monitor app. Below, notice that the compute is spiking at a set frequency which is every morning at 7 am.

    Usage Monitor
    Usage Monitor

  2. The following examples are used for simulation purposes and can create a memory and CPU spike that will be moved to an ECN node. They are intended to be run on a test or trial instance and not a production instance. The size of the spike can be adjusted by increasing or decreasing the number of rows in the table.

    SQL
    SELECT AVG(CPU) AS "CPU Usage %" FROM M_LOAD_HISTORY_HOST WHERE TIME > ADD_SECONDS(CURRENT_TIMESTAMP, -60);  --avg of the past 1 minute
    SELECT AVG(MEMORY_USED/1024/1024/1024) AS "Memory Used GB" FROM M_LOAD_HISTORY_HOST WHERE TIME > ADD_SECONDS(CURRENT_TIMESTAMP, -60);
    SELECT MEMORY_SIZE/1024/1024/1024 AS MEM_GB, DURATION_MICROSEC/1000000/60 AS DUR_MIN, CPU_TIME/1000000 AS CPU_TIME_SECS, STATEMENT_STRING, STATEMENT_START_TIME, * FROM M_EXPENSIVE_STATEMENTS ORDER BY MEMORY_SIZE DESC; --requires expensive tracing to be enabled
    
    CREATE USER USER4 PASSWORD "Password4"  NO FORCE_FIRST_PASSWORD_CHANGE SET USERGROUP DEFAULT;
    GRANT CATALOG READ TO USER4; 
    GRANT SELECT ON SCHEMA _SYS_STATISTICS TO USER4;  --Used by the Elastic Compute Node tab
    GRANT WORKLOAD ADMIN TO USER4; 
    CONNECT USER4 PASSWORD Password4;
    GRANT ALL PRIVILEGES ON SCHEMA USER4 TO DBADMIN;
    
    CREATE TABLE MYTABLE(VAL1 DOUBLE);
    --Demonstrates how an expensive query is made using cross joins
    INSERT INTO MYTABLE VALUES(1);
    INSERT INTO MYTABLE VALUES(2);
    INSERT INTO MYTABLE VALUES(3);
    SELECT * FROM MYTABLE T1, MYTABLE T2, MYTABLE T3;
    
    CREATE OR REPLACE PROCEDURE POPULATE_MYTABLE(NUMOFROWS INT) LANGUAGE SQLSCRIPT AS
    BEGIN
        USING SQLSCRIPT_PRINT AS PRTLIB;
        DECLARE i INT;
        TRUNCATE TABLE USER4.MYTABLE;
        FOR i IN 1 .. :NUMOFROWS DO
            INSERT INTO MYTABLE VALUES(RAND_SECURE());
        END FOR;
    END;
    
    CREATE OR REPLACE PROCEDURE CPU_SPIKE() LANGUAGE SQLSCRIPT AS
    BEGIN
        USING SQLSCRIPT_PRINT AS PRTLIB;
        SELECT SUM(T1.VAL1 + T2.VAL1 + T3.VAL1) FROM USER4.MYTABLE T1, USER4.MYTABLE T2, USER4.MYTABLE T3;
    END;
    
    CALL POPULATE_MYTABLE(2000);
    
    --9 seconds and 32 seconds of CPU time each call
    CALL CPU_SPIKE();
    CALL CPU_SPIKE();
    CALL CPU_SPIKE();
    CALL CPU_SPIKE();
    CALL CPU_SPIKE();
    CALL CPU_SPIKE();
    
    CREATE OR REPLACE PROCEDURE CPU_AND_MEMORY_SPIKE() LANGUAGE SQLSCRIPT AS
    BEGIN
        USING SQLSCRIPT_PRINT AS PRTLIB;
        WITH 
        A AS (SELECT DISTINCT VAL1 AS A1 FROM USER4.MYTABLE ORDER BY VAL1 DESC),
        B AS (SELECT DISTINCT VAL1 AS B1 FROM USER4.MYTABLE ORDER BY VAL1 ASC),
        C AS (SELECT DISTINCT VAL1 AS C1 FROM USER4.MYTABLE ORDER BY VAL1 DESC)
        SELECT TOP 1 DISTINCT A1 + B1 + C1 FROM A, B, C;
    END;
    
    CALL POPULATE_MYTABLE(750);
    
    --8 seconds, 30 sec CPU time, 9 GB of memory each call
    CALL CPU_AND_MEMORY_SPIKE();
    CALL CPU_AND_MEMORY_SPIKE();
    CALL CPU_AND_MEMORY_SPIKE();
    CALL CPU_AND_MEMORY_SPIKE();
    CALL CPU_AND_MEMORY_SPIKE();
    CALL CPU_AND_MEMORY_SPIKE();
    
    SELECT AVG(CPU) AS "CPU Usage" FROM M_LOAD_HISTORY_HOST WHERE TIME > ADD_SECONDS(CURRENT_TIMESTAMP, -60);  --avg of the past 1 minute
    SELECT AVG(MEMORY_USED) AS "Memory Used" FROM M_LOAD_HISTORY_HOST WHERE TIME > ADD_SECONDS(CURRENT_TIMESTAMP, -60);

    After calling the stored procedure CPU_SPIKE and CPU_AND_MEMORY_SPIKE, you can see that the CPU and memory usage has spiked, and you may also see an alert. Note that the metrics shown are polled once a minute, so the procedures are run multiple times.

    spike shown
    spike shown

    The following SQL statement can also be used if expensive statement tracing is enabled.

    SQL
    SELECT START_TIME, STATEMENT_STRING, DURATION_MICROSEC, MEMORY_SIZE, CPU_TIME, DB_USER FROM M_EXPENSIVE_STATEMENTS;
Step 2 Create an ECN
+
Step 3 Create a workload class
+
Step 4 Route to ECN with a hint
+
Step 5 Replicate a table to the ECN
+
Step 6 Remove the workload class and ECN
+
Step 7 Node.js app demonstrating prepared statements and the option routeDirectExecute on statement routing
+
Step 8 Procedure to check if the ECN is started
+
Step 9 ECN sample script
+
Step 10 Use SAP Automation Pilot to schedule the provisioning of an ECN
+
Step 11 ECN advisor
+
Step 12 Knowledge check
+

Resources

Discussion

Share feedback on this tutorial or join the conversation in SAP Community.

Submit detailed feedback Discuss in Community
Steps
Step 1 of 12
1. Identify tasks to be run on an Elastic Compute Node (ECN) 2. Create an ECN 3. Create a workload class 4. Route to ECN with a hint 5. Replicate a table to the ECN 6. Remove the workload class and ECN 7. Node.js app demonstrating prepared statements and the option routeDirectExecute on statement routing 8. Procedure to check if the ECN is started 9. ECN sample script 10. Use SAP Automation Pilot to schedule the provisioning of an ECN 11. ECN advisor 12. Knowledge check

Learn more →