Ray应用

当需要在数据库中执行AI、机器学习或大规模数据分析任务时,传统方法通常要求将数据迁移至外部计算集群。这一过程不仅增加了系统架构的复杂性,还带来了额外的数据传输成本和延迟。PolarDB PostgreSQL集成了Ray应用(即PolarDB Ray),使您能够直接在数据库内部利用Python生态和Ray分布式计算框架执行这些复杂任务,从而显著提升数据处理和人工智能推理的效率,并有效降低成本。

功能简介

Ray是一个开源的分布式计算框架,专为大规模AIPython应用而设计。PolarDB通过内置Ray应用,将这个强大的计算能力与数据库深度融合。这意味着您可以直接在数据库中编写和执行Python代码,利用Pandas、NumPy、Scikit-learn、PyTorch等丰富的AI/ML库来处理存储在数据库中的数据。无论是进行模型训练、数据预处理,还是执行复杂的向量计算,都可以在数据库内一站式完成,无需在数据库和外部计算环境之间来回移动数据。

优势

  • Serverless架构:提供永不缩容的稳态节点,以支撑常态业务。同时,敏态节点能够根据实时流量自动进行伸缩,兼顾稳定性与成本效益。

  • 高可用Ray Head节点支持高可用容灾能力,确保集群的稳定运行。

  • 安全可靠:

    • 通过安全容器提供运行时隔离,保障代码执行环境的安全。

    • 支持多租户隔离,防止租户间信息泄露。

    • Ray DashboardRay Job提交均支持用户名/密码及JWT鉴权,防止未授权访问。

  • 一体化元数据管理:与PolarDB集群处于同一专有网络VPC下,基于PolarDB Ray处理的元数据可直接存储在PolarDB集群中,无需额外网络配置即可实现数据交互。

  • 统一资源池:提供统一的CPU资源池,并支持GPU Worker,为不同类型的计算任务提供灵活的资源支持。

  • 存储服务:支持挂载PolarDB文件系统(Polar File System,简称PolarFS)2.0高性能版存储,可通过文件接口直接读写数据。

  • 开源定制PolarDB Ray作为开源Ray的下游,与开源Ray生态实现无缝兼容。同时,为开发者提供定制化的优化与增强服务。

适用范围

您的集群形态需为:集中式PolarDB PostgreSQL集群,暂不支持PolarDB PostgreSQL分布式版集群。

费用说明

  • 组件费用Ray应用分别收取其Head节点和每个Worker节点的费用,费用根据您选择的组件规格(CPU和内存)和购买时长计算。

    单个组件价格信息

    中国内地

    节点规格码

    CPU和内存

    价格(元/月)

    价格(元/小时)

    polar.app.g2.medium

    24 GB

    250

    0.52

    polar.app.g4.medium

    28 GB

    270

    0.56

    polar.app.g2.large

    48 GB

    475

    0.99

    polar.app.g4.large

    416 GB

    630

    1.31

    polar.app.g2.xlarge

    816 GB

    1,000

    2.08

    polar.app.g4.xlarge

    832 GB

    1,240

    2.58

    polar.app.g2.2xlarge

    1632 GB

    2,000

    4.17

    polar.app.g4.2xlarge

    1664 GB

    2,400

    5.00

    polar.app.g2.4xlarge

    3264 GB

    4,000

    8.32

    polar.app.g4.4xlarge

    32128 GB

    4,320

    8.96

    polar.app.g4.6xlarge

    48192 GB

    6,000

    12.48

    polar.app.g8.6xlarge

    48384 GB

    6,480

    13.44

    polar.app.g2.8xlarge

    64128 GB

    8,000

    16.64

    polar.app.g4.8xlarge

    64256 GB

    8,640

    17.92

    polar.app.g8.8xlarge

    64512 GB

    14,080

    29.32

    polar.app.g8.12xlarge

    88710 GB

    19,360

    40.31

    polar.app.g8.15xlarge

    120920 GB

    26,400

    54.98

    polar.app.g8.23xlarge

    1801800 GB

    39,600

    82.46

    中国(香港)

    节点规格码

    CPU和内存

    价格(元/月)

    价格(元/小时)

    polar.app.g2.medium

    24 GB

    400

    0.832

    polar.app.g4.medium

    28 GB

    432

    0.896

    polar.app.g2.large

    48 GB

    760

    1.584

    polar.app.g4.large

    416 GB

    1,008

    2.096

    polar.app.g2.xlarge

    816 GB

    1,600

    3.330

    polar.app.g4.xlarge

    832 GB

    1,984

    4.130

    polar.app.g2.2xlarge

    1632 GB

    3,200

    6.670

    polar.app.g4.2xlarge

    1664 GB

    3,840

    8.000

    polar.app.g2.4xlarge

    3264 GB

    6,400

    13.31

    polar.app.g4.4xlarge

    32128 GB

    6,912

    14.34

    polar.app.g4.6xlarge

    48192 GB

    9,600

    19.97

    polar.app.g8.6xlarge

    48384 GB

    10,368

    21.50

    polar.app.g2.8xlarge

    64128 GB

    12,800

    26.62

    polar.app.g4.8xlarge

    64256 GB

    13,824

    28.67

    polar.app.g8.8xlarge

    64512 GB

    22,528

    46.91

    polar.app.g8.12xlarge

    88710 GB

    30,976

    64.50

    polar.app.g8.15xlarge

    120920 GB

    42,240

    87.97

    polar.app.g8.23xlarge

    1801800 GB

    63,360

    131.94

    日本(东京)

    节点规格码

    CPU和内存

    价格(元/月)

    价格(元/小时)

    polar.app.g2.medium

    24 GB

    400

    0.832

    polar.app.g4.medium

    28 GB

    432

    0.896

    polar.app.g2.large

    48 GB

    760

    1.584

    polar.app.g4.large

    416 GB

    1,008

    2.096

    polar.app.g2.xlarge

    816 GB

    1,600

    3.330

    polar.app.g4.xlarge

    832 GB

    1,984

    4.130

    polar.app.g2.2xlarge

    1632 GB

    3,200

    6.670

    polar.app.g4.2xlarge

    1664 GB

    3,840

    8.000

    polar.app.g2.4xlarge

    3264 GB

    6,400

    13.31

    polar.app.g4.4xlarge

    32128 GB

    6,912

    14.34

    polar.app.g4.6xlarge

    48192 GB

    9,600

    19.97

    polar.app.g8.6xlarge

    48384 GB

    10,368

    21.50

    polar.app.g2.8xlarge

    64128 GB

    12,800

    26.62

    polar.app.g4.8xlarge

    64256 GB

    13,824

    28.67

    polar.app.g8.8xlarge

    64512 GB

    22,528

    46.91

    polar.app.g8.12xlarge

    88710 GB

    30,976

    64.50

    polar.app.g8.15xlarge

    120920 GB

    42,240

    87.97

    polar.app.g8.23xlarge

    1801800 GB

    63,360

    131.94

    韩国

    节点规格码

    CPU和内存

    价格(元/月)

    价格(元/小时)

    polar.app.g2.medium

    24 GB

    400

    0.832

    polar.app.g4.medium

    28 GB

    432

    0.896

    polar.app.g2.large

    48 GB

    760

    1.584

    polar.app.g4.large

    416 GB

    1,008

    2.096

    polar.app.g2.xlarge

    816 GB

    1,600

    3.330

    polar.app.g4.xlarge

    832 GB

    1,984

    4.130

    polar.app.g2.2xlarge

    1632 GB

    3,200

    6.670

    polar.app.g4.2xlarge

    1664 GB

    3,840

    8.000

    polar.app.g2.4xlarge

    3264 GB

    6,400

    13.31

    polar.app.g4.4xlarge

    32128 GB

    6,912

    14.34

    polar.app.g4.6xlarge

    48192 GB

    9,600

    19.97

    polar.app.g8.6xlarge

    48384 GB

    10,368

    21.50

    polar.app.g2.8xlarge

    64128 GB

    12,800

    26.62

    polar.app.g4.8xlarge

    64256 GB

    13,824

    28.67

    polar.app.g8.8xlarge

    64512 GB

    22,528

    46.91

    polar.app.g8.12xlarge

    88710 GB

    30,976

    64.50

    polar.app.g8.15xlarge

    120920 GB

    42,240

    87.97

    polar.app.g8.23xlarge

    1801800 GB

    63,360

    131.94

    新加坡

    节点规格码

    CPU和内存

    价格(元/月)

    价格(元/小时)

    polar.app.g2.medium

    24 GB

    400

    0.832

    polar.app.g4.medium

    28 GB

    432

    0.896

    polar.app.g2.large

    48 GB

    760

    1.584

    polar.app.g4.large

    416 GB

    1,008

    2.096

    polar.app.g2.xlarge

    816 GB

    1,600

    3.330

    polar.app.g4.xlarge

    832 GB

    1,984

    4.130

    polar.app.g2.2xlarge

    1632 GB

    3,200

    6.670

    polar.app.g4.2xlarge

    1664 GB

    3,840

    8.000

    polar.app.g2.4xlarge

    3264 GB

    6,400

    13.31

    polar.app.g4.4xlarge

    32128 GB

    6,912

    14.34

    polar.app.g4.6xlarge

    48192 GB

    9,600

    19.97

    polar.app.g8.6xlarge

    48384 GB

    10,368

    21.50

    polar.app.g2.8xlarge

    64128 GB

    12,800

    26.62

    polar.app.g4.8xlarge

    64256 GB

    13,824

    28.67

    polar.app.g8.8xlarge

    64512 GB

    22,528

    46.91

    polar.app.g8.12xlarge

    88710 GB

    30,976

    64.50

    polar.app.g8.15xlarge

    120920 GB

    42,240

    87.97

    polar.app.g8.23xlarge

    1801800 GB

    63,360

    131.94

    马来西亚(吉隆坡)

    节点规格码

    CPU和内存

    价格(元/月)

    价格(元/小时)

    polar.app.g2.medium

    24 GB

    400

    0.832

    polar.app.g4.medium

    28 GB

    432

    0.896

    polar.app.g2.large

    48 GB

    760

    1.584

    polar.app.g4.large

    416 GB

    1,008

    2.096

    polar.app.g2.xlarge

    816 GB

    1,600

    3.330

    polar.app.g4.xlarge

    832 GB

    1,984

    4.130

    polar.app.g2.2xlarge

    1632 GB

    3,200

    6.670

    polar.app.g4.2xlarge

    1664 GB

    3,840

    8.000

    polar.app.g2.4xlarge

    3264 GB

    6,400

    13.31

    polar.app.g4.4xlarge

    32128 GB

    6,912

    14.34

    polar.app.g4.6xlarge

    48192 GB

    9,600

    19.97

    polar.app.g8.6xlarge

    48384 GB

    10,368

    21.50

    polar.app.g2.8xlarge

    64128 GB

    12,800

    26.62

    polar.app.g4.8xlarge

    64256 GB

    13,824

    28.67

    polar.app.g8.8xlarge

    64512 GB

    22,528

    46.91

    polar.app.g8.12xlarge

    88710 GB

    30,976

    64.50

    polar.app.g8.15xlarge

    120920 GB

    42,240

    87.97

    polar.app.g8.23xlarge

    1801800 GB

    63,360

    131.94

    印度尼西亚(雅加达)

    节点规格码

    CPU和内存

    价格(元/月)

    价格(元/小时)

    polar.app.g2.medium

    24 GB

    350

    0.728

    polar.app.g4.medium

    28 GB

    378

    0.784

    polar.app.g2.large

    48 GB

    665

    1.386

    polar.app.g4.large

    416 GB

    882

    1.834

    polar.app.g2.xlarge

    816 GB

    1,400

    2.910

    polar.app.g4.xlarge

    832 GB

    1,736

    3.610

    polar.app.g2.2xlarge

    1632 GB

    2,800

    5.840

    polar.app.g4.2xlarge

    1664 GB

    3,360

    7.000

    polar.app.g2.4xlarge

    3264 GB

    5,600

    11.65

    polar.app.g4.4xlarge

    32128 GB

    6,048

    12.54

    polar.app.g4.6xlarge

    48192 GB

    8,400

    17.47

    polar.app.g8.6xlarge

    48384 GB

    9,072

    18.82

    polar.app.g2.8xlarge

    64128 GB

    11,200

    23.30

    polar.app.g4.8xlarge

    64256 GB

    12,096

    25.09

    polar.app.g8.8xlarge

    64512 GB

    19,712

    41.05

    polar.app.g8.12xlarge

    88710 GB

    27,104

    56.43

    polar.app.g8.15xlarge

    120920 GB

    36,960

    76.97

    polar.app.g8.23xlarge

    1801800 GB

    55,440

    115.44

    菲律宾

    节点规格码

    CPU和内存

    价格(元/月)

    价格(元/小时)

    polar.app.g2.medium

    24 GB

    350

    0.728

    polar.app.g4.medium

    28 GB

    378

    0.784

    polar.app.g2.large

    48 GB

    665

    1.386

    polar.app.g4.large

    416 GB

    882

    1.834

    polar.app.g2.xlarge

    816 GB

    1,400

    2.910

    polar.app.g4.xlarge

    832 GB

    1,736

    3.610

    polar.app.g2.2xlarge

    1632 GB

    2,800

    5.840

    polar.app.g4.2xlarge

    1664 GB

    3,360

    7.000

    polar.app.g2.4xlarge

    3264 GB

    5,600

    11.65

    polar.app.g4.4xlarge

    32128 GB

    6,048

    12.54

    polar.app.g4.6xlarge

    48192 GB

    8,400

    17.47

    polar.app.g8.6xlarge

    48384 GB

    9,072

    18.82

    polar.app.g2.8xlarge

    64128 GB

    11,200

    23.30

    polar.app.g4.8xlarge

    64256 GB

    12,096

    25.09

    polar.app.g8.8xlarge

    64512 GB

    19,712

    41.05

    polar.app.g8.12xlarge

    88710 GB

    27,104

    56.43

    polar.app.g8.15xlarge

    120920 GB

    36,960

    76.97

    polar.app.g8.23xlarge

    1801800 GB

    55,440

    115.44

    泰国(曼谷)

    节点规格码

    CPU和内存

    价格(元/月)

    价格(元/小时)

    polar.app.g2.medium

    24 GB

    350

    0.728

    polar.app.g4.medium

    28 GB

    378

    0.784

    polar.app.g2.large

    48 GB

    665

    1.386

    polar.app.g4.large

    416 GB

    882

    1.834

    polar.app.g2.xlarge

    816 GB

    1,400

    2.910

    polar.app.g4.xlarge

    832 GB

    1,736

    3.610

    polar.app.g2.2xlarge

    1632 GB

    2,800

    5.840

    polar.app.g4.2xlarge

    1664 GB

    3,360

    7.000

    polar.app.g2.4xlarge

    3264 GB

    5,600

    11.65

    polar.app.g4.4xlarge

    32128 GB

    6,048

    12.54

    polar.app.g4.6xlarge

    48192 GB

    8,400

    17.47

    polar.app.g8.6xlarge

    48384 GB

    9,072

    18.82

    polar.app.g2.8xlarge

    64128 GB

    11,200

    23.30

    polar.app.g4.8xlarge

    64256 GB

    12,096

    25.09

    polar.app.g8.8xlarge

    64512 GB

    19,712

    41.05

    polar.app.g8.12xlarge

    88710 GB

    27,104

    56.43

    polar.app.g8.15xlarge

    120920 GB

    36,960

    76.97

    polar.app.g8.23xlarge

    1801800 GB

    55,440

    115.44

    德国(法兰克福)

    节点规格码

    CPU和内存

    价格(元/月)

    价格(元/小时)

    polar.app.g2.medium

    24 GB

    350

    0.728

    polar.app.g4.medium

    28 GB

    378

    0.784

    polar.app.g2.large

    48 GB

    665

    1.386

    polar.app.g4.large

    416 GB

    882

    1.834

    polar.app.g2.xlarge

    816 GB

    1,400

    2.910

    polar.app.g4.xlarge

    832 GB

    1,736

    3.610

    polar.app.g2.2xlarge

    1632 GB

    2,800

    5.840

    polar.app.g4.2xlarge

    1664 GB

    3,360

    7.000

    polar.app.g2.4xlarge

    3264 GB

    5,600

    11.65

    polar.app.g4.4xlarge

    32128 GB

    6,048

    12.54

    polar.app.g4.6xlarge

    48192 GB

    8,400

    17.47

    polar.app.g8.6xlarge

    48384 GB

    9,072

    18.82

    polar.app.g2.8xlarge

    64128 GB

    11,200

    23.30

    polar.app.g4.8xlarge

    64256 GB

    12,096

    25.09

    polar.app.g8.8xlarge

    64512 GB

    19,712

    41.05

    polar.app.g8.12xlarge

    88710 GB

    27,104

    56.43

    polar.app.g8.15xlarge

    120920 GB

    36,960

    76.97

    polar.app.g8.23xlarge

    1801800 GB

    55,440

    115.44

    英国(伦敦)

    节点规格码

    CPU和内存

    价格(元/月)

    价格(元/小时)

    polar.app.g2.medium

    24 GB

    350

    0.728

    polar.app.g4.medium

    28 GB

    378

    0.784

    polar.app.g2.large

    48 GB

    665

    1.386

    polar.app.g4.large

    416 GB

    882

    1.834

    polar.app.g2.xlarge

    816 GB

    1,400

    2.910

    polar.app.g4.xlarge

    832 GB

    1,736

    3.610

    polar.app.g2.2xlarge

    1632 GB

    2,800

    5.840

    polar.app.g4.2xlarge

    1664 GB

    3,360

    7.000

    polar.app.g2.4xlarge

    3264 GB

    5,600

    11.65

    polar.app.g4.4xlarge

    32128 GB

    6,048

    12.54

    polar.app.g4.6xlarge

    48192 GB

    8,400

    17.47

    polar.app.g8.6xlarge

    48384 GB

    9,072

    18.82

    polar.app.g2.8xlarge

    64128 GB

    11,200

    23.30

    polar.app.g4.8xlarge

    64256 GB

    12,096

    25.09

    polar.app.g8.8xlarge

    64512 GB

    19,712

    41.05

    polar.app.g8.12xlarge

    88710 GB

    27,104

    56.43

    polar.app.g8.15xlarge

    120920 GB

    36,960

    76.97

    polar.app.g8.23xlarge

    1801800 GB

    55,440

    115.44

    美国(硅谷)

    节点规格码

    CPU和内存

    价格(元/月)

    价格(元/小时)

    polar.app.g1.tiny

    11 GB

    13.2

    0.024

    polar.app.g2.small

    12 GB

    21.6

    0.048

    polar.app.g2.medium

    24 GB

    300

    0.624

    polar.app.g4.medium

    28 GB

    324

    0.672

    polar.app.g2.large

    48 GB

    570

    1.188

    polar.app.g4.large

    416 GB

    756

    1.572

    polar.app.g2.xlarge

    816 GB

    1,200

    2.50

    polar.app.g4.xlarge

    832 GB

    1,488

    3.10

    polar.app.g2.2xlarge

    1632 GB

    2,400

    5.00

    polar.app.g4.2xlarge

    1664 GB

    2,880

    6.00

    polar.app.g2.4xlarge

    3264 GB

    4,800

    9.98

    polar.app.g4.4xlarge

    32128 GB

    5,184

    10.75

    polar.app.g4.6xlarge

    48192 GB

    7,200

    14.98

    polar.app.g8.6xlarge

    48384 GB

    7,776

    16.13

    polar.app.g2.8xlarge

    64128 GB

    9,600

    19.97

    polar.app.g4.8xlarge

    64256 GB

    10,368

    21.50

    polar.app.g8.8xlarge

    64512 GB

    16,896

    35.18

    polar.app.g8.12xlarge

    88710 GB

    23,232

    48.37

    polar.app.g8.15xlarge

    120920 GB

    31,680

    65.98

    polar.app.g8.23xlarge

    1801800 GB

    47,520

    98.95

    美国(弗吉尼亚)

    节点规格码

    CPU和内存

    价格(元/月)

    价格(元/小时)

    polar.app.g1.tiny

    11 GB

    13.2

    0.024

    polar.app.g2.small

    12 GB

    21.6

    0.048

    polar.app.g2.medium

    24 GB

    300

    0.624

    polar.app.g4.medium

    28 GB

    324

    0.672

    polar.app.g2.large

    48 GB

    570

    1.188

    polar.app.g4.large

    416 GB

    756

    1.572

    polar.app.g2.xlarge

    816 GB

    1,200

    2.50

    polar.app.g4.xlarge

    832 GB

    1,488

    3.10

    polar.app.g2.2xlarge

    1632 GB

    2,400

    5.00

    polar.app.g4.2xlarge

    1664 GB

    2,880

    6.00

    polar.app.g2.4xlarge

    3264 GB

    4,800

    9.98

    polar.app.g4.4xlarge

    32128 GB

    5,184

    10.75

    polar.app.g4.6xlarge

    48192 GB

    7,200

    14.98

    polar.app.g8.6xlarge

    48384 GB

    7,776

    16.13

    polar.app.g2.8xlarge

    64128 GB

    9,600

    19.97

    polar.app.g4.8xlarge

    64256 GB

    10,368

    21.50

    polar.app.g8.8xlarge

    64512 GB

    16,896

    35.18

    polar.app.g8.12xlarge

    88710 GB

    23,232

    48.37

    polar.app.g8.15xlarge

    120920 GB

    31,680

    65.98

    polar.app.g8.23xlarge

    1801800 GB

    47,520

    98.95

  • 存储费用Ray应用所产生的数据和文件不额外计费,但Ray JobPolarDB PostgreSQL集群或PolarFS存储写入的数据将收取相应的存储空间费用

  • 流量与带宽:不收取费用。

快速体验

1. (可选)创建PolarDB PostgreSQL集群

若您没有符合适用范围的集群,或现有的集群因业务原因不便进行更改,您可在PolarDB控制台上另行创建一个集群以体验Ray应用

2. 创建Ray应用

  1. 登录PolarDB控制台,在集群详情页中,单击左侧导航栏中的AI能力 > AI应用,并单击新建AI应用image

  2. 在应用购买页面中,请根据您的需求选择适合的配置:

    配置项

    说明

    付费类型

    • 包年包月:预付费模式。在创建应用时,您需选择固定规格的资源,并预先支付应用的费用。购买周期越长,所享受的折扣也越大。该模式一般适用于业务需求长期稳定的场景。

    • 按量付费:后付费模式。在创建应用时,您需选择固定规格的资源,但无需提前支付应用的费用。该模式根据您实际使用的时长进行计费,一般适用于业务需求灵活的场景。

    引擎

    固定为PolarDB

    地域

    选择应用所在的地理位置

    说明
    • 应用购买完成后,不支持更改地域。

    • 应用需与PolarDB PostgreSQL集群位于同一地域。因此,请选择与PolarDB PostgreSQL集群相同的地域。

    • 建议将应用与需要连接的ECS创建在同一地域,否则它们将无法通过内网(私网)实现互通,只能通过外网(公网)进行通信,这将无法充分发挥最佳性能。

    架构

    固定为AI应用

    PolarDB集群

    选择需要创建应用的PolarDB集群。

    AI应用

    AI应用类型。您需要选择Ray

    组件集

    一个Ray应用可以包含一个Head组件和多个Worker组件,这些组件构成应用的组件集。

    • Head组件:托管的Ray Head节点。

    • CPU Worker组件:托管的Ray Worker节点。

    说明
    • Head组件的最小数量和最大数量只能为1。

    • CPU Worker组件的最小数量可设为0,最小数量即为Ray稳态Worker节点的数量。最大数量与最小数量之间的差值决定了Ray应用Serverless形态下的Worker节点的最大数量。

    • GPU Worker组件目前处于邀测阶段,如需申请试用,请提交工单联系我们为您开启该功能。

    AI应用名

    您可以填写自定义的应用名称。

    说明

    不能以http://或者https://开头,且长度2~256个字符。

    存储类型

    固定为PolarFS

    Polarfs实例ID/名称

    选择您PolarDB PostgreSQL集群中创建的PolarFS实例。

    说明
    • PolarFS目前处于邀测阶段,如需申请试用,请提交工单联系我们为您开启该功能。

    • 仅支持高性能版PolarFS实例。

    网络类型

    固定为专有网络

    VPC网络

    自动填写为源PolarDB集群的专有网络,无需手动填写。

    可用区和交换机

    配置VPC网络的交换机,建议选择与PolarDB PostgreSQL集群的主可用区相同的交换机,以发挥最佳网络性能。

    如果已有的交换机无法满足您的要求,您可以自行创建交换机

    安全组

    配置应用的安全组。

    购买数量

    选择需要购买的应用数量。

    说明

    付费类型包年包月时,支持配置。

    购买时长

    选择应用的购买时长。

    说明

    付费类型包年包月时,支持配置。

    自动续费

    配置是否开启自动续费。为避免因忘记续费而导致业务中断,建议您开启自动续费。

    说明

    付费类型包年包月时,支持配置。

  3. 购买成功后,请返回集群的AI应用页面,即可查看新创建的应用。

    说明

    系统需要3~5分钟创建应用,请耐心等待。

3. 连接Ray应用

  • 配置应用白名单:在AI应用列表页面,单击您的应用ID进入应用详情页,并在白名单页签,新增IP白名单分组选择安全组配置已有白名单分组。

    说明
    • 应用白名单与集群白名单相互独立,需进行单独配置。

    • 如果您的ECS实例需要访问应用,可在ECS实例详情页面查看ECS实例的IP地址,并将其填写至IP白名单中。

      • 如果您的ECS实例与应用位于同一VPC内,您可以填写ECS的私网IP地址或其所在VPC网段。

      • 如果您的ECS实例与应用不在同一VPC内,您可填写ECS的公网IP地址,或添加ECS所在的安全组。

    • 如果您本地的服务器、电脑或其他云服务器需要访问应用,请将其公网IP地址添加到IP白名单中。

    image

  • 获取连接地址:在AI应用列表页面,单击您的应用ID进入应用详情页,在拓扑图页签中查看公网地址私网地址

    说明
    • 公网地址需单独申请,请单击申请按钮以进行申请。

    • 公网地址仅提供IP地址和端口,不提供域名。如您有相关需求,可自行绑定域名。

    image

  • 获取应用配置信息:在AI应用列表页面,单击您的应用ID进入应用详情页,在配置页签中查看相关配置信息。image

4. 开发应用

您可以通过公网直接访问应用,在AI应用列表页面中单击开发应用,以跳转至Ray Dashboard的公网地址。或者直接在浏览器地址栏中输入应用的公网IP地址和端口,以访问Ray Dashboard

说明
  • 请先将您的公网IP地址添加至应用白名单中。

  • Ray Dashboard的用户名与密码为应用配置信息中的secret.dashboard.usernamesecret.dashboard.password

image

5. 通过SDK提交Ray Job

您可以使用Ray SDK以编程方式提交Ray Job

  1. 准备环境

    说明

    请先在您的本地环境中安装Python 3环境。

    安装Ray SDK:

    pip install ray    
  2. 准备代码文件
    您需要在您的工作目录下,新建两个Ray应用脚本。一个用于业务处理,一个用于提交Job。工作目录结构示例如下:

    - working-dir/
     - script.py # 您的Ray业务逻辑脚本
     - ray_job_submit.py # 用于提交作业的脚本

    脚本示例如下:

    script.py

    import ray
    import time
    
    
    @ray.remote
    def retrieve_task(item, db):
        time.sleep(item / 10.)
        return item, db[item]
    
    
    if __name__ == "__main__":
        database = [
            "Learning", "Ray", "Flexible", "Distributed", "Python", "for",
            "Machine", "Learning"
        ]
        ray.init()
        db_object_ref = ray.put(database)
        retrieve_refs = [
            retrieve_task.remote(item, db_object_ref) for item in [0, 2, 4, 6]
        ]
        result = [print(data) for data in ray.get(retrieve_refs)]
    

    ray_job_submit.py

    import os
    import json
    import base64
    import hmac
    import hashlib
    import requests
    
    from datetime import timezone, timedelta, datetime
    from requests.auth import HTTPBasicAuth
    from ray.job_submission import JobSubmissionClient
    
    # 您的 Ray Dashboard 地址
    address = os.getenv("RAY_DASHBOARD_ADDRESS")
    
    # 您可以直接使用 `secret.jwt.anonKey` 进行认证
    token = os.getenv("RAY_ANON_TOKEN")
    
    # 您也可以使用 `secret.jwt.secret` 生成 JWT
    secret = os.getenv("RAY_JWT_SECRET")
    header = {"alg": "HS256", "typ": "JWT"}
    
    now = datetime.now(tz=timezone.utc)
    payload = {
      "sub": "anon",
      "iat": int(now.timestamp()),
      "exp": int((now + timedelta(hours=12)).timestamp()),
      "iss": "ray-dashboard",
      "aud": "ray-dashboard-client"
    }
    
    header_encoded = base64.urlsafe_b64encode(
      json.dumps(header,
                 separators=(',', ':')).encode()).decode('utf-8').rstrip('=')
    payload_encoded = base64.urlsafe_b64encode(
      json.dumps(payload,
                 separators=(',', ':')).encode()).decode('utf-8').rstrip('=')
    
    message = f"{header_encoded}.{payload_encoded}"
    signature = hmac.new(secret.encode(), message.encode(),
                         hashlib.sha256).digest()
    signature_encoded = base64.urlsafe_b64encode(signature).decode('utf-8').rstrip(
      '=')
    token = f"{message}.{signature_encoded}"
    
    # 您也可以通过POST /api/auth/token 获取 JWT 进行认证,您需要提供用户名和密码
    username = os.getenv('RAY_USERNAME')
    password = os.getenv('RAY_PASSWORD')
    response = requests.post(f'{address}/api/auth/token',
                             auth=HTTPBasicAuth(username, password),
                             timeout=5)
    
    if response.status_code == 200:
      token_data = response.json()
      token = token_data['access_token']
    else:
      print(f"❌ Failed to get JWT: {response.status_code}")
    
    client = JobSubmissionClient(address,
                                 headers={"Authorization": f"Bearer {token}"})
    
    job_id = client.submit_job(
      # Entrypoint shell command to execute
      entrypoint="python script.py",
      # Path to the local directory that contains the script.py file
      runtime_env={"working_dir": "./"})
    
    print(job_id)
  3. 配置并运行

    1. Ray应用配置页面查看以下信息,并将其设置为环境变量或在submit_job.py脚本中进行替换

      变量

      对应配置项

      示例值

      RAY_DASHBOARD_ADDRESS

      Ray应用连接地址,根据您的实际环境选择公网或私网。

      http://123.xxx.xxx.xxx:8265

      RAY_ANON_TOKEN

      secret.jwt.anonKey

      eyJhbGciOi...

      RAY_JWT_SECRET

      secret.jwt.secret

      tNhVxysSRD...

      RAY_USERNAME

      secret.dashboard.username

      admin

      RAY_PASSWORD

      secret.dashboard.password

      UTLof$rMVM...

    2. 在您的工作目录下,执行提交脚本:

      python ray_job_submit.py
    3. 执行成功后,您可以登录Ray Dashboard,在Jobs页面查看已提交作业的运行状态。image