从实测出发,掌握 NebulaGraph Exchange 性能最大化的秘密

pczhy
发布于 2023-2-28 15:12
6827浏览
0收藏

01. 环境准备


🔧硬件:

  • Spark 集群:三台机器,每台 96 core,256 G 内存
  • NebulaGraph 集群:三台机器,每台 128 core,252 G 内存,SSD,双万兆网卡
  • 数据:LDBC sf100 数据

💻软件:

  • Spark 版本:2.4.4
  • NebulaGraph 版本:3.3.0

02. NebulaGraph 优化配置


在进行大批量数据导入时,可以调整 NebulaGraph Storage 服务和 Graph 服务的配置,以达到最大导入性能。请根据 NebulaGraph 的配置描述和你的实际环境资源进行参数调整。

在本次实践中,NebulaGraph 的集群配置针对以下几个配置项进行了修改,其他均采用默认配置:

"storaged":
    --rocksdb_block_cache=81920,
    --heartbeat_interval_secs=10,
    --reader_handlers=64,
    --num_worker_threads=64,
    --rocksdb_db_options={"max_subcompactions":"64","max_background_jobs":"64"}
         
"graphd":
     --storage_client_timeout_ms=360000,
     --session_idle_timeout_secs=2880,
     --max_sessions_per_ip_per_user=500000,
     --num_worker_threads=64
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.


 NebulaGraph Storage 服务优化

在这里简单讲一下几个 Storage 服务优化配置项:

  • --rocksdb_block_cache 数据在内存缓存大小,默认是 4 MB,大批量数据导入时可以设置到当前内存的 1/3;
  • --num_worker_threads storaged 的 RPC 服务的工作线程数量,默认 32;
  • --query_concurrently 为 true 表示 storaged 会并发地读取数据,false 表示 storaged 是单线程取数;
  • --rocksdb_db_options={"max_subcompactions":"48","max_background_jobs":"48"}:可用来加速自动 Compaction 过程;
  • --rocksdb_column_family_options={"write_buffer_size":"67108864","max_write_buffer_number":"5"},在刚开始导入大量数据时可以将 disable_auto_compaction 选项设置为 true,提升写入的性能;
  • --wal_ttl=600 在大量数据导入时,若磁盘不充裕,那么该参数需调小,不然可能会因为产生大量的 wal 导致磁盘空间被撑满。

 NebulaGraph Graph 服务优化

再简单地罗列下 Graph 服务相关的一些优化配置项:

  • --storage_client_timeout_ms 为 graphd 与 storaged 通信的超时时间;
  • --max_sessions_per_ip_per_user 是单用户单 IP 客户端允许创建的最大 session 数;
  • --system_memory_high_watermark_ratio 设置内存使用量超过多少时停止计算,表示资源的占用率,一般设置为 0.8~1.0 之间;
  • --num_worker_threads 为 graphd 的 RPC 服务的工作线程数量,默认 32。

03. NebulaGraph DDL

下面,我们通过这些语句来创建下 Schema 方便后续导入数据:

CREATE SPACE sf100(vid_type=int64,partition_num=100,replica_factor=3);
USE sf100;
CREATE TAG IF NOT EXISTS `Place`(`name` string,`url` string,`type` string);
CREATE TAG IF NOT EXISTS `Comment`(`creationDate` string,`locationIP` string,`browserUsed` string,`content` string,`length` int);
CREATE TAG IF NOT EXISTS `Organisation`(`type` string,`name` string,`url` string);
CREATE TAG IF NOT EXISTS `Person`(`firstName` string,`lastName` string,`gender` string,`birthday` string,`creationDate` string,`locationIP` string,`browserUsed` string);
CREATE TAG IF NOT EXISTS `Tagclass`(`name` string,`url` string);
CREATE TAG IF NOT EXISTS `Forum`(`title` string,`creationDate` string);
CREATE TAG IF NOT EXISTS `Post`(`imageFile` string,`creationDate` string,`locationIP` string,`browserUsed` string,`language` string,`content` string,`length` int);
CREATE TAG IF NOT EXISTS `Tag`(`name` string,`url` string);
CREATE EDGE IF NOT EXISTS `IS_PART_OF`();
CREATE EDGE IF NOT EXISTS `LIKES`(`creationDate` string);
CREATE EDGE IF NOT EXISTS `HAS_CREATOR`();
CREATE EDGE IF NOT EXISTS `HAS_INTEREST`();
CREATE EDGE IF NOT EXISTS `IS_SUBCLASS_OF`();
CREATE EDGE IF NOT EXISTS `IS_LOCATED_IN`();
CREATE EDGE IF NOT EXISTS `HAS_MODERATOR`();
CREATE EDGE IF NOT EXISTS `HAS_TAG`();
CREATE EDGE IF NOT EXISTS `WORK_AT`(`workFrom` int);
CREATE EDGE IF NOT EXISTS `REPLY_OF`();
CREATE EDGE IF NOT EXISTS `STUDY_AT`(`classYear` int);
CREATE EDGE IF NOT EXISTS `CONTAINER_OF`();
CREATE EDGE IF NOT EXISTS `HAS_MEMBER`(`joinDate` string);
CREATE EDGE IF NOT EXISTS `KNOWS`(`creationDate` string);
CREATE EDGE IF NOT EXISTS `HAS_TYPE`();
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.


04. LDBC sf100 数据集的数据量

该表展示了各类点边的数据量

Label

Amount

Comment

220,096,052

Forum

4,080,604

Organisation

7,955

Person

448,626

Place

1,460

Post

57,987,023

Tag

16,080

Tagclass

71

CONTAINER_OF

57,987,023

HAS_CREATOR

278,083,075

HAS_INTEREST

10,471,962

HAS_MEMBER

179,874,360

HAS_MODERATOR

4,080,604

HAS_TAG

383,613,078

HAS_TYPE

16,080

IS_LOCATED_IN

278,539,656

IS_PART_OF

1,454

IS_SUBCLASS_OF

70

KNOWS

19,941,198

LIKES

341,473,012

REPLY_OF

2,200,960,52

STUDY_AT

359,212

WORK_AT

976,349


05. NebulaGraph Exchange 配置

重点来了,看好这个配置,如果下次还有小伙伴配置配错了导致数据导入报错的话,我可是要丢这篇文章的链接了。app.conf 如下:

{
 # Spark 相关配置
 spark: {
   app: {
     name: Nebula Exchange
   }
 }

 # NebulaGraph 相关配置
 nebula: {
   address:{
     graph:["192.168.xx.8:9669","192.168.xx.9:9669","192.168.xx.10:9669"] //因为实验环境是集群,这里配置了 3 台机器的 graphd 地址
     meta:["192.168.xx.8:9559"] //无需配置多台机器的 meta 地址,随机配一个就行
   }
   user: root
   pswd: nebula
   space: sf100 // 之前 Schema 创建的图空间名

   # NebulaGraph 客户端连接参数设置
   connection {
     timeout: 30000 //超过 30000ms 无响应会报错
   }

   error: {
     max: 32
     output: /tmp/errors
   }

   # 使用 Google 的 RateLimiter 限制发送到 NebulaGraph 的请求
   rate: {
     limit: 1024
     timeout: 1000
   }
 }

# 这里开始处理点数据,进行之前的 Schema 和数据映射
 tags: [
   {
     name: Person // tagName 为 Person
     type: {
       source: csv //指定数据源类型
       sink: client //指定如何将点数据导入 NebulaGraph,client 或 sst
     }
     path: "hdfs://192.168.xx.2:9000/ldbc/sf100/social_network/dynamic/person.csv" // 数据文件的所在路径,如果文件存储在 HDFS 上,用双引号括起路径,以 hdfs:// 开头,例如 "hdfs://ip:port/xx/xx"。如果文件存储在本地,用双引号括起路径,以 file:// 开头,例如 "file:///tmp/xx.csv"。
     fields: [_c1,_c2,_c3,_c4,_c5,_c6,_c7] // 无表头,_cn 表示表头
     nebula.fields: [firstName,lastName,gender,birthday,creationDate,locationIP,browserUsed] // tag 的属性映射,_c1 对应 firstName
     vertex: _c0 // 指定 vid 的列
     batch: 2000 // 单次请求写入多少点数据
     partition: 180 // Spark partition 数
     separator: | // 属性分隔符
     header: false // 无表头设置,false 表示无表头
   }

   {
     name: Place
     type: {
       source: csv
       sink: client
     }
     path: "hdfs://192.168.xx.2:9000/ldbc/sf100/social_network/static/place.csv"
     fields: [_c1,_c2,_c3]
     nebula.fields: [name, type, url]
     vertex: _c0
     batch: 2000
     partition: 180
     separator: |
     header: false
   }


   {
     name: Organisation
     type: {
       source: csv
       sink: client
     }
     path: "hdfs://192.168.xx.2:9000/ldbc/sf100/social_network/static/organisation.csv"
     fields: [_c1,_c2,_c3]
     nebula.fields: [name, type,url]
     vertex: _c0
     batch: 2000
     partition: 180
     separator: |
     header: false
   }

   {
     name: Post
     type: {
       source: csv
       sink: client
     }
     path: "hdfs://192.168.xx.2:9000/ldbc/sf100/social_network/dynamic/post.csv"
     fields: [_c1,_c2,_c3,_c4,_c5,_c6,_c7]
     nebula.fields: [imageFile,creationDate,locationIP,browserUsed,language,content,length]
     vertex: _c0
     batch: 2000
     partition: 180
     separator: |
     header: false
   }

   {
     name: Comment
     type: {
       source: csv
       sink: client
     }
     path: "hdfs://192.168.xx.2:9000/ldbc/sf100/social_network/dynamic/comment.csv"
     fields: [_c1,_c2,_c3,_c4,_c5]
     nebula.fields: [creationDate,locationIP,browserUsed,content,length]
     vertex: _c0
     batch: 2000
     partition: 180
     separator: |
     header: false
   }

   {
     name: Forum
     type: {
       source: csv
       sink: client
     }
     path: "hdfs://192.168.xx.2:9000/ldbc/sf100/social_network/dynamic/forum.csv"
     fields: [_c1,_c2]
     nebula.fields: [creationDate,title]
     vertex: _c0
     batch: 2000
     partition: 180
     separator: |
     header: false
   }

   {
     name: Tag
     type: {
       source: csv
       sink: client
     }
     path: "hdfs://192.168.xx.2:9000/ldbc/sf100/social_network/static/tag.csv"
     fields: [_c1,_c2]
     nebula.fields: [name,url]
     vertex: _c0
     batch: 2000
     partition: 180
     separator: |
     header: false
   }

   {
     name: Tagclass
     type: {
       source: csv
       sink: client
     }
     path: "hdfs://192.168.xx.2:9000/ldbc/sf100/social_network/static/tagclass.csv"
     fields: [_c1,_c2]
     nebula.fields: [name,url]
     vertex: _c0
     batch: 2000
     partition: 180
     separator: |
     header: false
   }
 ]

 # 开始处理边数据
 edges: [
   {
     name: KNOWS //边类型
     type: {
       source: csv //文件类型
       sink: client //同上 tag 的 sink 说明
     }
     path: "hdfs://192.168.xx.2:9000/ldbc/sf100/social_network/dynamic/person_knows_person.csv" //同上 tag 的 path 说明
     fields: [_c2] //无表头的,设定 _c2 为表头
     nebula.fields: [creationDate] // 属性值和表头映射,这里为 KNOW 类型边中的 creationDate 属性
     source: {
       field: _c0 // 源数据中作为 KNOW 类型边起点的列
     }
     target: {
       field: _c1 // 源数据中作为 KNOW 类型边终点的列 
     }
     batch: 2000 // 单批次写入的最大边数据
     partition: 180 //同上 tag 的 partition 说明
     separator: | //同上 tag 的 separator 说明
     header: false // 同上 tag 的 header 说明
   }

   {
     name: LIKES
     type: {
       source: csv
       sink: client
     }
     path: "hdfs://192.168.xx.2:9000/ldbc/sf100/social_network/dynamic/person_likes_comment.csv"
     fields: [_c2]
     nebula.fields: [creationDate]
     source: {
       field: _c0
     }
     target: {
       field: _c1
     }
     batch: 2000
     partition: 180
     separator: |
     header: false
   }

   {
     name: LIKES
     type: {
       source: csv
       sink: client
     }
     path: "hdfs://192.168.xx.2:9000/ldbc/sf100/social_network/dynamic/person_likes_post.csv"
     fields: [_c2]
     nebula.fields: [creationDate]
     source: {
       field: _c0
     }
     target: {
       field: _c1
     }
     batch: 2000
     partition: 180
     separator: |
     header: false
   }

   {
     name: HAS_TAG
     type: {
       source: csv
       sink: client
     }
     path: "hdfs://192.168.xx.2:9000/ldbc/sf100/social_network/dynamic/forum_hasTag_tag.csv"
     fields: []
     nebula.fields: []
     source: {
       field: _c0
     }
     target: {
       field: _c1
     }
     batch: 2000
     partition: 180
     separator: |
     header: false
   }

    {
     name: HAS_TAG
     type: {
       source: csv
       sink: client
     }
     path: "hdfs://192.168.xx.2:9000/ldbc/sf100/social_network/dynamic/comment_hasTag_tag.csv"
     fields: []
     nebula.fields: []
     source: {
       field: _c0
     }
     target: {
       field: _c1
     }
     batch: 2000
     partition: 180
     separator: |
     header: false
   }

   {
     name: HAS_TAG
     type: {
       source: csv
       sink: client
     }
     path: "hdfs://192.168.xx.2:9000/ldbc/sf100/social_network/dynamic/post_hasTag_tag.csv"
     fields: []
     nebula.fields: []
     source: {
       field: _c0
     }
     target: {
       field: _c1
     }
     batch: 2000
     partition: 180
     separator: |
     header: false
   }

   {
     name: HAS_TYPE
     type: {
       source: csv
       sink: client
     }
     path: "hdfs://192.168.xx.2:9000/ldbc/sf100/social_network/static/tag_hasType_tagclass.csv"
     fields: []
     nebula.fields: []
     source: {
       field: _c0
     }
     target: {
       field: _c1
     }
     batch: 2000
     partition: 180
     separator: |
     header: false
   }

   {
     name: HAS_MODERATOR
     type: {
       source: csv
       sink: client
     }
     path: "hdfs://192.168.xx.2:9000/ldbc/sf100/social_network/dynamic/forum_hasModerator_person.csv"
     fields: []
     nebula.fields: []
     source: {
       field: _c0
     }
     target: {
       field: _c1
     }
     batch: 2000
     partition: 180
     separator: |
     header: false
   }

   {
     name: HAS_MEMBER
     type: {
       source: csv
       sink: client
     }
     path: "hdfs://192.168.xx.2:9000/ldbc/sf100/social_network/dynamic/forum_hasMember_person.csv"
     fields: [_c2]
     nebula.fields: [joinDate]
     source: {
       field: _c0
     }
     target: {
       field: _c1
     }
     batch: 2000
     partition: 180
     separator: |
     header: false
   }

   {
     name: HAS_INTEREST
     type: {
       source: csv
       sink: client
     }
     path: "hdfs://192.168.xx.2:9000/ldbc/sf100/social_network/dynamic/person_hasInterest_tag.csv"
     fields: []
     nebula.fields: []
     source: {
       field: _c0
     }
     target: {
       field: _c1
     }
     batch: 2000
     partition: 180
     separator: |
     header: false
   }

   {
     name: HAS_CREATOR
     type: {
       source: csv
       sink: client
     }
     path: "hdfs://192.168.xx.2:9000/ldbc/sf100/social_network/dynamic/post_hasCreator_person.csv"
     fields: []
     nebula.fields: []
     source: {
       field: _c0
     }
     target: {
       field: _c1
     }
     batch: 2000
     partition: 180
     separator: |
     header: false
   }

   {
     name: HAS_CREATOR
     type: {
       source: csv
       sink: client
     }
     path: "hdfs://192.168.xx.2:9000/ldbc/sf100/social_network/dynamic/comment_hasCreator_person.csv"
     fields: []
     nebula.fields: []
     source: {
       field: _c0
     }
     target: {
       field: _c1
     }
     batch: 2000
     partition: 180
     separator: |
     header: false
   }

   {
     name: IS_PART_OF
     type: {
       source: csv
       sink: client
     }
     path: "hdfs://192.168.xx.2:9000/ldbc/sf100/social_network/static/place_isPartOf_place.csv"
     fields: []
     nebula.fields: []
     source: {
       field: _c0
     }
     target: {
       field: _c1
     }
     batch: 2000
     partition: 180
     separator: |
     header: false
   }

   {
     name: CONTAINER_OF
     type: {
       source: csv
       sink: client
     }
     path: "hdfs://192.168.xx.2:9000/ldbc/sf100/social_network/dynamic/forum_containerOf_post.csv"
     fields: []
     nebula.fields: []
     source: {
       field: _c0
     }
     target: {
       field: _c1
     }
     batch: 2000
     partition: 180
     separator: |
     header: false
   }

   {
     name: IS_LOCATED_IN
     type: {
       source: csv
       sink: client
     }
     path: "hdfs://192.168.xx.2:9000/ldbc/sf100/social_network/dynamic/person_isLocatedIn_place.csv"
     fields: []
     nebula.fields: []
     source: {
       field: _c0
     }
     target: {
       field: _c1
     }
     batch: 2000
     partition: 180
     separator: |
     header: false
   }

    {
     name: IS_LOCATED_IN
     type: {
       source: csv
       sink: client
     }
     path: "hdfs://192.168.xx.2:9000/ldbc/sf100/social_network/dynamic/post_isLocatedIn_place.csv"
     fields: []
     nebula.fields: []
     source: {
       field: _c0
     }
     target: {
       field: _c1
     }
     batch: 2000
     partition: 180
     separator: |
     header: false
   }

   {
     name: IS_LOCATED_IN
     type: {
       source: csv
       sink: client
     }
     path: "hdfs://192.168.xx.2:9000/ldbc/sf100/social_network/dynamic/comment_isLocatedIn_place.csv"
     fields: []
     nebula.fields: []
     source: {
       field: _c0
     }
     target: {
       field: _c1
     }
     batch: 2000
     partition: 180
     separator: |
     header: false
   }

   {
     name: IS_LOCATED_IN
     type: {
       source: csv
       sink: client
     }
     path: "hdfs://192.168.xx.2:9000/ldbc/sf100/social_network/static/organisation_isLocatedIn_place.csv"
     fields: []
     nebula.fields: []
     source: {
       field: _c0
     }
     target: {
       field: _c1
     }
     batch: 2000
     partition: 180
     separator: |
     header: false
   }


   {
     name: REPLY_OF
     type: {
       source: csv
       sink: client
     }
     path: "hdfs://192.168.xx.2:9000/ldbc/sf100/social_network/dynamic/comment_replyOf_comment.csv"
     fields: []
     nebula.fields: []
     source: {
       field: _c0
     }
     target: {
       field: _c1
     }
     batch: 2000
     partition: 180
     separator: |
     header: false
   }

   {
     name: REPLY_OF
     type: {
       source: csv
       sink: client
     }
     path: "hdfs://192.168.xx.2:9000/ldbc/sf100/social_network/dynamic/comment_replyOf_post.csv"
     fields: []
     nebula.fields: []
     source: {
       field: _c0
     }
     target: {
       field: _c1
     }
     batch: 2000
     partition: 180
     separator: |
     header: false
   }

   {
     name: STUDY_AT
     type: {
       source: csv
       sink: client
     }
     path: "hdfs://192.168.xx.2:9000/ldbc/sf100/social_network/dynamic/person_studyAt_organisation.csv"
     fields: [_c2]
     nebula.fields: [classYear]
     source: {
       field: _c0
     }
     target: {
       field: _c1
     }
     batch: 2000
     partition: 180
     separator: |
     header: false
   }

   {
     name: WORK_AT
     type: {
       source: csv
       sink: client
     }
     path: "hdfs://192.168.xx.2:9000/ldbc/sf100/social_network/dynamic/person_workAt_organisation.csv"
     fields: [_c2]
     nebula.fields: [workFrom]
     source: {
       field: _c0
     }
     target: {
       field: _c1
     }
     batch: 2000
     partition: 180
     separator: |
     header: false
   }


   {
     name: IS_SUBCLASS_OF
     type: {
       source: csv
       sink: client
     }
     path: "hdfs://192.168.xx.2:9000/ldbc/sf100/social_network/static/tagclass_isSubclassOf_tagclass.csv"
     fields: []
     nebula.fields: []
     source: {
       field: _c0
     }
     target: {
       field: _c1
     }
     batch: 2000
     partition: 180
     separator: |
     header: false
   }
 ]
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
  • 106.
  • 107.
  • 108.
  • 109.
  • 110.
  • 111.
  • 112.
  • 113.
  • 114.
  • 115.
  • 116.
  • 117.
  • 118.
  • 119.
  • 120.
  • 121.
  • 122.
  • 123.
  • 124.
  • 125.
  • 126.
  • 127.
  • 128.
  • 129.
  • 130.
  • 131.
  • 132.
  • 133.
  • 134.
  • 135.
  • 136.
  • 137.
  • 138.
  • 139.
  • 140.
  • 141.
  • 142.
  • 143.
  • 144.
  • 145.
  • 146.
  • 147.
  • 148.
  • 149.
  • 150.
  • 151.
  • 152.
  • 153.
  • 154.
  • 155.
  • 156.
  • 157.
  • 158.
  • 159.
  • 160.
  • 161.
  • 162.
  • 163.
  • 164.
  • 165.
  • 166.
  • 167.
  • 168.
  • 169.
  • 170.
  • 171.
  • 172.
  • 173.
  • 174.
  • 175.
  • 176.
  • 177.
  • 178.
  • 179.
  • 180.
  • 181.
  • 182.
  • 183.
  • 184.
  • 185.
  • 186.
  • 187.
  • 188.
  • 189.
  • 190.
  • 191.
  • 192.
  • 193.
  • 194.
  • 195.
  • 196.
  • 197.
  • 198.
  • 199.
  • 200.
  • 201.
  • 202.
  • 203.
  • 204.
  • 205.
  • 206.
  • 207.
  • 208.
  • 209.
  • 210.
  • 211.
  • 212.
  • 213.
  • 214.
  • 215.
  • 216.
  • 217.
  • 218.
  • 219.
  • 220.
  • 221.
  • 222.
  • 223.
  • 224.
  • 225.
  • 226.
  • 227.
  • 228.
  • 229.
  • 230.
  • 231.
  • 232.
  • 233.
  • 234.
  • 235.
  • 236.
  • 237.
  • 238.
  • 239.
  • 240.
  • 241.
  • 242.
  • 243.
  • 244.
  • 245.
  • 246.
  • 247.
  • 248.
  • 249.
  • 250.
  • 251.
  • 252.
  • 253.
  • 254.
  • 255.
  • 256.
  • 257.
  • 258.
  • 259.
  • 260.
  • 261.
  • 262.
  • 263.
  • 264.
  • 265.
  • 266.
  • 267.
  • 268.
  • 269.
  • 270.
  • 271.
  • 272.
  • 273.
  • 274.
  • 275.
  • 276.
  • 277.
  • 278.
  • 279.
  • 280.
  • 281.
  • 282.
  • 283.
  • 284.
  • 285.
  • 286.
  • 287.
  • 288.
  • 289.
  • 290.
  • 291.
  • 292.
  • 293.
  • 294.
  • 295.
  • 296.
  • 297.
  • 298.
  • 299.
  • 300.
  • 301.
  • 302.
  • 303.
  • 304.
  • 305.
  • 306.
  • 307.
  • 308.
  • 309.
  • 310.
  • 311.
  • 312.
  • 313.
  • 314.
  • 315.
  • 316.
  • 317.
  • 318.
  • 319.
  • 320.
  • 321.
  • 322.
  • 323.
  • 324.
  • 325.
  • 326.
  • 327.
  • 328.
  • 329.
  • 330.
  • 331.
  • 332.
  • 333.
  • 334.
  • 335.
  • 336.
  • 337.
  • 338.
  • 339.
  • 340.
  • 341.
  • 342.
  • 343.
  • 344.
  • 345.
  • 346.
  • 347.
  • 348.
  • 349.
  • 350.
  • 351.
  • 352.
  • 353.
  • 354.
  • 355.
  • 356.
  • 357.
  • 358.
  • 359.
  • 360.
  • 361.
  • 362.
  • 363.
  • 364.
  • 365.
  • 366.
  • 367.
  • 368.
  • 369.
  • 370.
  • 371.
  • 372.
  • 373.
  • 374.
  • 375.
  • 376.
  • 377.
  • 378.
  • 379.
  • 380.
  • 381.
  • 382.
  • 383.
  • 384.
  • 385.
  • 386.
  • 387.
  • 388.
  • 389.
  • 390.
  • 391.
  • 392.
  • 393.
  • 394.
  • 395.
  • 396.
  • 397.
  • 398.
  • 399.
  • 400.
  • 401.
  • 402.
  • 403.
  • 404.
  • 405.
  • 406.
  • 407.
  • 408.
  • 409.
  • 410.
  • 411.
  • 412.
  • 413.
  • 414.
  • 415.
  • 416.
  • 417.
  • 418.
  • 419.
  • 420.
  • 421.
  • 422.
  • 423.
  • 424.
  • 425.
  • 426.
  • 427.
  • 428.
  • 429.
  • 430.
  • 431.
  • 432.
  • 433.
  • 434.
  • 435.
  • 436.
  • 437.
  • 438.
  • 439.
  • 440.
  • 441.
  • 442.
  • 443.
  • 444.
  • 445.
  • 446.
  • 447.
  • 448.
  • 449.
  • 450.
  • 451.
  • 452.
  • 453.
  • 454.
  • 455.
  • 456.
  • 457.
  • 458.
  • 459.
  • 460.
  • 461.
  • 462.
  • 463.
  • 464.
  • 465.
  • 466.
  • 467.
  • 468.
  • 469.
  • 470.
  • 471.
  • 472.
  • 473.
  • 474.
  • 475.
  • 476.
  • 477.
  • 478.
  • 479.
  • 480.
  • 481.
  • 482.
  • 483.
  • 484.
  • 485.
  • 486.
  • 487.
  • 488.
  • 489.
  • 490.
  • 491.
  • 492.
  • 493.
  • 494.
  • 495.
  • 496.
  • 497.
  • 498.
  • 499.
  • 500.
  • 501.
  • 502.
  • 503.
  • 504.
  • 505.
  • 506.
  • 507.
  • 508.
  • 509.
  • 510.
  • 511.
  • 512.
  • 513.
  • 514.
  • 515.
  • 516.
  • 517.
  • 518.
  • 519.
  • 520.
  • 521.
  • 522.
  • 523.
  • 524.
  • 525.
  • 526.
  • 527.
  • 528.
  • 529.
  • 530.
  • 531.
  • 532.
  • 533.
  • 534.
  • 535.
  • 536.
  • 537.
  • 538.
  • 539.
  • 540.
  • 541.
  • 542.
  • 543.
  • 544.
  • 545.
  • 546.
  • 547.
  • 548.
  • 549.
  • 550.
  • 551.
  • 552.
  • 553.
  • 554.
  • 555.
  • 556.
  • 557.
  • 558.
  • 559.
  • 560.
  • 561.
  • 562.
  • 563.
  • 564.
  • 565.
  • 566.
  • 567.
  • 568.
  • 569.
  • 570.
  • 571.
  • 572.
  • 573.
  • 574.
  • 575.
  • 576.
  • 577.
  • 578.
  • 579.
  • 580.
  • 581.
  • 582.
  • 583.
  • 584.
  • 585.
  • 586.
  • 587.
  • 588.
  • 589.
  • 590.
  • 591.
  • 592.
  • 593.
  • 594.
  • 595.
  • 596.
  • 597.
  • 598.
  • 599.
  • 600.
  • 601.
  • 602.
  • 603.
  • 604.
  • 605.
  • 606.
  • 607.
  • 608.
  • 609.
  • 610.
  • 611.
  • 612.
  • 613.
  • 614.
  • 615.
  • 616.
  • 617.
  • 618.
  • 619.
  • 620.
  • 621.
  • 622.
  • 623.
  • 624.
  • 625.
  • 626.
  • 627.
  • 628.
  • 629.
  • 630.
  • 631.
  • 632.
  • 633.
  • 634.
  • 635.
  • 636.
  • 637.
  • 638.
  • 639.
  • 640.
  • 641.
  • 642.
  • 643.
  • 644.
  • 645.
  • 646.
  • 647.
  • 648.
  • 649.
  • 650.
  • 651.
  • 652.
  • 653.
  • 654.
  • 655.

在上面的第一次配置 tag 和 edge 的时候,我增加了一些字段说明,具体的大家可以翻阅下 NebulaGraph Exchange 的文档来获得更详细的说明:https://docs.nebula-graph.com.cn/3.3.0/nebula-exchange/use-exchange/ex-ug-import-from-csv/


06. Spark 提交参数配置

Spark 集群有三个节点,每个节点可用配置为 96 core,256 G 内存。

从实测出发,掌握 NebulaGraph Exchange 性能最大化的秘密-鸿蒙开发者社区

配置的 Spark 提交命令如下:

spark-submit --master "spark://127.0.0.1:7077" \
--driver-memory=2G \
--executor-memory=30G \
--total-executor-cores=120 \
--executor-cores=10 \
--num-executors=3 \ // 对 standalone 模式无效
--class com.vesoft.nebula.exchange.Exchange \
nebula-exchange_spark_2.4-3.3.0.jar -c app.conf
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.

07. 测试结果

在测试中,我们修改了 NebulaGraph Exchange 配置文件中的 batch 数、partition 数和 spark-submit 提交命令中的 total-executor-cores 数来调整导入的并发度,导入结果如下图:

从实测出发,掌握 NebulaGraph Exchange 性能最大化的秘密-鸿蒙开发者社区

当 max_subcompaction 为 64 时,NebulaGraph 机器的磁盘和网络 io 使用情况(时间 15:00 之后的部分)如下:

从实测出发,掌握 NebulaGraph Exchange 性能最大化的秘密-鸿蒙开发者社区

在进行导入时,storaged 服务的 max_subcompaction 配置对导入性能有很大影响。当 NebulaGraph 机器的 io 达到极限时,应用层的配置参数对导入性能影响甚微。


08. 关键性能字段

这里,再单独拉出来关键字段来讲下,大家可以根据自身的数据量、机器配置来调整相关参数。

 NebulaGraph Exchange 的 app.conf

这里需要重点关注前面两个字段,当然后面的字段也不是不重要:

  • partition根据 Spark 集群的机器核数决定 partition 配置项的值。partition 的值是 spark-submit 命令中配置的总核数的 2-3 倍,其中:总核数 = num-executors * executor-cores。
  • batch,client 向 graphd 发送的一个请求中有多少条数据。在该实践中采用的 LDBC 数据集的 tag 属性不超过 10 个,设置的 batch 数为 2,000。如果 tag 或 edgeType 属性多且字节数多,batch 可以调小,反之,则调大。
  • nebula.connection.timeout,NebulaGraph 客户端与服务端连接和请求的超时时间。若网络环境较差,数据导入过程出现 "connection timed out",可适当调大该参数。(read timed out 与该配置无关)
  • nebula.error.max,允许发生的最大失败次数。当客户端向服务端发送请求的失败数超过该值,则 NebulaGraph Exchange 退出。
  • nebula.error.output,导入失败的数据会被存入该目录。
  • nebula.rate.limit,采用令牌桶限制 NebulaGraph Exchange 向 NebulaGraph 发送请求的速度,limit 值为每秒向令牌桶中创建的令牌数
  • nebula.rate.timeout,当速度受阻无法获取令牌时,允许最大等待的时间,超过该时间获取不到令牌则 NebulaGraph Exchange 退出。单位:ms。

Spark 的 spark-submit

这里主要讲下 spark-submit 命令关键性使用指引,详细内容可参考 Spark 文档:https://spark.apache.org/docs/latest/spark-standalone.html

spark-submit 有多种提交方式,这里以 standalone 和 yarn 两种为例:

  • standalone 模式:spark://master_ip:port
  • yarn 模式:由于 yarn cluster 模式下会随机选择一台机器作为 driver 进行 job 提交。如果作为 driver 的那个机器中没有 NebulaGraph Exchange 的 jar 包和配置文件,会出现 "ClassNotFound" 的异常,参考论坛帖子:https://discuss.nebula-graph.com.cn/t/topic/9766。所以,yarn 模式下需要在 spark-submit 命令中配置以下参数:

--files app.conf \
--conf spark.driver.extraClassPath=./ \   // 指定 NebulaGraph Exchange jar 包和配置文件所在的目录
--conf spark.executor.extraClassPath=./ \ // 指定 NebulaGraph Exchange jar 包和配置文件所在的目录
  • 1.
  • 2.
  • 3.

除了提交模式之外,spark-submit 还有一些参数需要关注下:

  • --driver-memory,给 spark driver 节点分配的内存。client 模式(还有 sst 模式)导入时,该值可采用默认值不进行配置,因为没有 reduce 操作需要用到 driver 内存。
  • --executor-memory,根据源数据的 size M 和 partition 数 p 进行配置,可配置成 2*( M/p)。
  • --total-executor-cores,standalone 模式下 Spark 应用程序可用的总 cores,可根据 Spark 集群的总 cores 来配。
  • --executor-cores,每个 executor 分配的核数。在每个 executor 内部,多个 core 意味着多线程共享 executor 的内存。可以设置为 5-10,根据集群节点核数自行调节。
  • --num-executors,yarn 模式下申请的 executor 的数量,根据集群节点数来配置。可以设置为 ((节点核数-其他程序预留核数)/executor-cores)*集群节点数,根据节点资源自行调节。比如,一个 Spark 集群有三台节点,每节点有 64 核,executor-cores 设置为 10,节点中为其他程序预留 14 核,则 num-executors 可设置为 15,由公式推断而出 ((64-14)/10)*3 = 15

其他调优

在该实践中,NebulaGraph 除第二步骤提到的优化配置,其他配置均采用系统默认配置,NebulaGraph Exchange 的导入并发度最小为 90,batch 为 2,000。当提高应用程序的并发度时或 batch 数时,导入性能无法再提升。因此可以在优化 NebulaGraph storaged 配置的基础上,适当调整并发度和 batch 数,在自己环境中得到两者的平衡,使导入过程达到一个最佳性能。

关于 Spark 的 total-executor-coresexecutor-coresnum-executors 和配置文件中的 partition 的关系:

  • 在 standalone 模式下,启动多少个 executor 是由 --total-executor-cores 和 --executor-cores 两个参数来决定的,如果设定的 --total-executor-cores 是 10,--executor-cores 是 5,则一共会启动两个 executor。此时给应用程序分配的总核数是 total-executor-cores 的值。
  • 在 yarn 模式下,启动多少个 executor 是由 num-executors 来决定的,此时给应用程序分配的总核数是 executor-cores * num-executors 的值。
  • 在 Spark 中可执行任务的 worker 一共是分配给应用程序的总 cores 数个,应用程序中的任务数有 partition 数个。如果任务数偏少,会导致前面设置的 executor 及 core 的参数无效,比如 partition 只有 1,那么 90% 的 executor 进程可能就一直在空闲着没有任务可执行。Spark 官网给出的建议是 partition 可设置为分配的总 cores 的 2-3 倍,如 executor 的总 CPU core 数量为 100,那么建议设置 partition 为 200 或 300。


如何选择数据导入工具

想必通过上面的内容大家对 NebulaGraph Exchange 的数据导入性能有了一定的了解,下图为 NebulaGraph 数据导入工具的分布图:

从实测出发,掌握 NebulaGraph Exchange 性能最大化的秘密-鸿蒙开发者社区

感兴趣的小伙伴可以阅读文档 https://docs.nebula-graph.com.cn/3.3.0/20.appendix/write-tools/ 了解具体的选择事项。


本文转载自公众号:Nebula Graph Community

分类
标签
已于2023-2-28 15:12:59修改
收藏
回复
举报


回复
    相关推荐