Serverless型執行個體使用指南

更新時間:
Copy as MD

本文為您介紹如何購買與使用Hologres Serverless型執行個體。

使用限制

  • Serverless型執行個體支援地區和可用性區域如下:

    地區

    可用性區域

    華東1(杭州)

    可用性區域J、K

    華東2(上海)

    可用性區域E、L

    華南1(深圳)

    可用性區域F、D

    華北2(北京)

    可用性區域I、L

    中國(香港)

    可用性區域B、D

    新加坡

    可用性區域A、C

  • 每個阿里雲帳號在每個地區下只支援建立1Serverless型執行個體。

功能介紹

Serverless型執行個體的功能如下(與計算群組型和通用型執行個體對比):

  • 每個Serverless型執行個體的可用計算資源量上限(Quota)為512 CU,仍支援SQL層級設定可用的資源量。詳情請參見Serverless Computing使用指南

  • Serverless型執行個體的全部讀寫請求都使用Serverless Computing資源執行,不支援手動設定hg_computing_resource參數。

  • Serverless型執行個體不支援查詢隊列Query Queue,所有請求均遵循Serverless Computing資源申請規則排隊規則

  • Serverless型執行個體支援的最大串連數是256個,詳情請參見串連數管理

  • Serverless型執行個體在儲存上的預設Shard數是16,執行個體內所有Table Group的總Shard數上限為128,不建議設定較大Shard數。詳情請參見Shard數管理

Serverless型執行個體不支援的功能如下:

Serverless型執行個體與其他產品對接情況如下:

  • Flink:不支援做Flink的源表。支援做Flink的維表和結果表,但由於Serverless型執行個體不支援Fixed Plan,會自動使用HQE執行,存在效能損失,建議充分測試後使用。

  • DataWorksData Integration:由於Serverless型執行個體不支援Fixed Plan,DataWorksData Integration的匯入任務會自動使用HQE執行,存在效能損失,建議充分測試後使用。

  • PAI-Rec:由於Serverless型執行個體不支援向量計算,不支援Fixed Plan,建議使用計算群組型執行個體對接PAI-Rec推薦系統。

Serverless型執行個體建立

  1. 單擊購買頁或登入Hologres管理主控台,單擊左側導覽列的實例清單,在執行個體列表頁單擊新增引擎實例

  2. 購買頁配置如下:

    配置項

    配置值

    商品類型

    獨享執行個體(隨用隨付)

    地區

    目標地區(Serverless型執行個體支援的地區)。

    執行個體類型

    Serverless

    可用性區域

    目標可用性區域。

    Virtual Private Cloud

    選擇您所建立的專用網路和交換器。具體操作請參見專用網路與交換器

    專用網路交換器

    執行個體名稱

    自訂命名。

    服務關聯角色

    已建立。如果是首次購買Hologres執行個體,需在購買頁底部單擊建立服務關聯角色

    資源群組

    預設資源群組。您也可以選擇建立其他資源群組。

  3. 完成配置後,單擊立即購買

  4. 確認訂單頁面,單擊立即開通

    Severless型執行個體將在數分鐘內建立完成。

Serverless型執行個體營運

自動停機

對於Serverless型執行個體,如果連續30天沒有資料寫入或資料查詢請求,執行個體會在第31自動停機。您可以通過以下步驟查看當前執行個體距自動停機的剩餘時間:

  1. 登入Hologres管理主控台

  2. 單擊左側導覽列的實例清單

  3. 單擊目標Serverless型執行個體。在執行個體詳情頁的基礎資訊中進行查看。

在停機狀態下,執行個體的儲存資料保留,仍會隨用隨付。執行個體的計算服務暫停,不會產生費用。如需重新啟用計算服務,只需在實例清單頁面中,單擊目標執行個體所在運行狀態列的恢復操作即可。

執行個體版本升級

對於Serverless型執行個體,為提升執行個體的穩定性和與Serverless Computing資源集區間的相容性,Hologres可能在您的可維護時間視窗內,自動將您的執行個體升級至最新穩定版本。除後台自動升級外,您可以自助升級至最新穩定版本。

Serverless型執行個體版本升級均採用熱升級方案,升級所帶來的影響詳情請參見升級方式

監控指標

Serverless型執行個體支援絕大部分的監控指標,詳情請參見Hologres管控台的監控指標。僅有部分不支援的功能沒有對應的指標,例如Fixed Plan、低頻訪問儲存以及Binlog消費等。

您可正常查看Serverless型執行個體的監控指標,並配置相應監控警示。

Serverless型執行個體使用

Serverless型執行個體的使用方式與計算群組型執行個體、通用型執行個體一致。您可以正常串連執行個體並執行請求。

本樣本以GitHub公開事件數目據為例,為您示範Serverless型執行個體的使用方法。步驟如下:

  1. 建立Serverless型執行個體

  2. 建立資料庫

  3. 一鍵匯入公用資料集或手動建立SQL查詢建立MaxCompute外表並匯入,命令如下:

    -- 建立schema用於建立外部表格
    CREATE SCHEMA IF NOT EXISTS hologres_foreign_dataset_github_event;
    
    -- 建立schema用於建立內表並匯入資料
    CREATE SCHEMA IF NOT EXISTS hologres_dataset_github_event;
    
    -- 建立外部表格
    DROP FOREIGN TABLE IF EXISTS hologres_foreign_dataset_github_event.dwd_github_events_odps;
    
    IMPORT FOREIGN SCHEMA "bigdata_public_dataset#github_events" LIMIT TO
    (
        dwd_github_events_odps
    ) 
    FROM SERVER odps_server INTO hologres_foreign_dataset_github_event OPTIONS(if_table_exist 'error',if_unsupported_type 'error');
    
    -- 建立內表
    DROP TABLE IF EXISTS hologres_dataset_github_event.hologres_github_event;
    BEGIN;
    CREATE TABLE hologres_dataset_github_event.hologres_github_event (
        id BIGINT,
        actor_id BIGINT,
        actor_login TEXT,
        repo_id BIGINT,
        repo_name TEXT,
        org_id BIGINT,
        org_login TEXT,
        type TEXT,
        created_at TIMESTAMP WITH TIME ZONE NOT NULL,
        action TEXT,
        iss_or_pr_id BIGINT,
        number BIGINT,
        comment_id BIGINT,
        commit_id TEXT,
        member_id BIGINT,
        rev_or_push_or_rel_id BIGINT,
        ref TEXT,
        ref_type TEXT,
        state TEXT,
        author_association TEXT,
        language TEXT,
        merged boolean,
        merged_at TIMESTAMP WITH TIME ZONE,
        additions BIGINT,
        deletions BIGINT,
        changed_files BIGINT,
        push_size BIGINT,
        push_distinct_size BIGINT,
        hr TEXT,
        month TEXT,
        year TEXT,
        ds TEXT
    );
    CALL set_table_property('hologres_dataset_github_event.hologres_github_event', 'distribution_key', 'id');
    CALL set_table_property('hologres_dataset_github_event.hologres_github_event', 'event_time_column', 'created_at');
    CALL set_table_property('hologres_dataset_github_event.hologres_github_event', 'clustering_key', 'created_at');
    
    COMMENT ON COLUMN hologres_dataset_github_event.hologres_github_event.id IS '事件ID';
    COMMENT ON COLUMN hologres_dataset_github_event.hologres_github_event.actor_id IS '事件發起人ID';
    COMMENT ON COLUMN hologres_dataset_github_event.hologres_github_event.actor_login IS '事件發起人登入名稱';
    COMMENT ON COLUMN hologres_dataset_github_event.hologres_github_event.repo_id IS 'repoID';
    COMMENT ON COLUMN hologres_dataset_github_event.hologres_github_event.repo_name IS 'repo名稱';
    COMMENT ON COLUMN hologres_dataset_github_event.hologres_github_event.org_id IS 'repo所屬組織ID';
    COMMENT ON COLUMN hologres_dataset_github_event.hologres_github_event.org_login IS 'repo所屬組織名稱';
    COMMENT ON COLUMN hologres_dataset_github_event.hologres_github_event.type IS '事件類型';
    COMMENT ON COLUMN hologres_dataset_github_event.hologres_github_event.created_at IS '事件發生時間';
    COMMENT ON COLUMN hologres_dataset_github_event.hologres_github_event.action IS '事件行為';
    COMMENT ON COLUMN hologres_dataset_github_event.hologres_github_event.iss_or_pr_id IS 'issue/pull_request ID';
    COMMENT ON COLUMN hologres_dataset_github_event.hologres_github_event.number IS 'issue/pull_request 序號';
    COMMENT ON COLUMN hologres_dataset_github_event.hologres_github_event.comment_id IS 'comment(評論)ID';
    COMMENT ON COLUMN hologres_dataset_github_event.hologres_github_event.commit_id IS '提交記錄ID';
    COMMENT ON COLUMN hologres_dataset_github_event.hologres_github_event.member_id IS '成員ID';
    COMMENT ON COLUMN hologres_dataset_github_event.hologres_github_event.rev_or_push_or_rel_id IS 'review/push/release ID';
    COMMENT ON COLUMN hologres_dataset_github_event.hologres_github_event.ref IS '建立/刪除的資源名稱';
    COMMENT ON COLUMN hologres_dataset_github_event.hologres_github_event.ref_type IS '建立/刪除的資源類型';
    COMMENT ON COLUMN hologres_dataset_github_event.hologres_github_event.state IS 'issue/pull_request/pull_request_review的狀態';
    COMMENT ON COLUMN hologres_dataset_github_event.hologres_github_event.author_association IS 'actorrepo之間的關係';
    COMMENT ON COLUMN hologres_dataset_github_event.hologres_github_event.language IS '程式設計語言';
    COMMENT ON COLUMN hologres_dataset_github_event.hologres_github_event.merged IS '是否接受合并';
    COMMENT ON COLUMN hologres_dataset_github_event.hologres_github_event.merged_at IS '代碼合并時間';
    COMMENT ON COLUMN hologres_dataset_github_event.hologres_github_event.additions IS '代碼增加行數';
    COMMENT ON COLUMN hologres_dataset_github_event.hologres_github_event.deletions IS '代碼減少行數';
    COMMENT ON COLUMN hologres_dataset_github_event.hologres_github_event.changed_files IS 'pull request 改變檔案數量';
    COMMENT ON COLUMN hologres_dataset_github_event.hologres_github_event.push_size IS '提交數量';
    COMMENT ON COLUMN hologres_dataset_github_event.hologres_github_event.push_distinct_size IS '不同的提交數量';
    COMMENT ON COLUMN hologres_dataset_github_event.hologres_github_event.hr IS '事件發生所在小時,如0023分,hr=00';
    COMMENT ON COLUMN hologres_dataset_github_event.hologres_github_event.month IS '事件發生所在月,如201510月,month=2015-10';
    COMMENT ON COLUMN hologres_dataset_github_event.hologres_github_event.year IS '事件發生所在年,如2015年,year=2015';
    COMMENT ON COLUMN hologres_dataset_github_event.hologres_github_event.ds IS '事件發生所在日,ds=yyyy-mm-dd';
    COMMIT;
    
    -- 匯入資料
    SET hg_experimental_serverless_computing_required_cores = 192;
    INSERT INTO hologres_dataset_github_event.hologres_github_event
    SELECT
        *
    FROM
        hologres_foreign_dataset_github_event.dwd_github_events_odps
    WHERE
        ds BETWEEN (CURRENT_DATE - interval '365 day')::text AND (CURRENT_DATE - interval '1 day')::text;
    RESET hg_computing_resource;
    
    -- 更新表的統計資訊
    ANALYZE hologres_dataset_github_event.hologres_github_event;
  4. 資料查詢

    例如查詢近一周最活躍(事件數目最多)的幾個專案。命令如下:

    SELECT
        repo_name,
        COUNT(*) AS events
    FROM
        hologres_dataset_github_event.hologres_github_event
    WHERE
        ds >= (CURRENT_DATE - INTERVAL '7 day')::text
    GROUP BY
        repo_name
    ORDER BY
        events DESC
    LIMIT 5;