首页 文章 精选 留言 我的

精选列表

搜索[镜像无法拉取],共10000篇文章
优秀的个人博客,低调大师

依赖单机尝鲜 Nebula Exchange 的 SST 导入

本文尝试分享下以最小方式(单机、容器化 Spark、Hadoop、Nebula Graph),快速趟一下 Nebula Exchange 中 SST 写入方式的步骤。本文适用于 v2.5 以上版本的 Nebula- Exchange。 原文链接: 国外访问:https://siwei.io/nebula-exchange-sst-2.x/ 国内访问:https://cn.siwei.io/nebula-exchange-sst-2.x/ 什么是 Nebula Exchange? 之前我在 Nebula Data Import Options 之中介绍过,Nebula Exchange 是一个 Nebula Graph 社区开源的 Spark Applicaiton,它专门用来支持批量或者流式地把数据导入 Nebula Graph Database 之中。 Nebula Exchange 支持多种多样的数据源(从 Apache Parquet、ORC、JSON、CSV、HBase、Hive MaxCompute 到 Neo4j、MySQL、ClickHouse,再有 Kafka、Pulsar,更多的数据源也在不断增加之中)。 如上图所示,在 Exchange 内部,从除了不同 Reader 可以读取不同数据源之外,在数据经过 Processor 处理之后通过 Writer写入(sink) Nebula Graph 图数据库的时候,除了走正常的 ServerBaseWriter 的写入流程之外,它还可以绕过整个写入流程,利用 Spark 的计算能力并行生成底层 RocksDB 的 SST 文件,从而实现超高性能的数据导入,这个 SST 文件导入的场景就是本文带大家上手熟悉的部分。 详细信息请参阅:Nebula Graph 手册:什么是 Nebula Exchange Nebula Graph 官方博客也有更多 Nebula Exchange 的实践文章 步骤概观 实验环境 配置 Exchange 生成 SST 文件 写入 SST 文件到 Nebula Graph 实验环境准备 为了最小化使用 Nebula Exchange 的 SST 功能,我们需要: 搭建一个 Nebula Graph 集群,创建导入数据的 Schema,我们选择使用 Docker-Compose 方式、利用 Nebula-Up 快速部署,并简单修改其网络,以方便同样容器化的 Exchange 程序对其访问。 搭建容器化的 Spark 运行环境 搭建容器化的 HDFS 1. 搭建 Nebula Graph 集群 借助于 Nebula-Up 我们可以在 Linux 环境下一键部署一套 Nebula Graph 集群: curl -fsSL nebula-up.siwei.io/install.sh | bash 待部署成功之后,我们需要对环境做一些修改,这里我做的修改其实就是两点: 只保留一个 metaD 服务 起用 Docker 的外部网络 详细修改的部分参考附录一 应用 docker-compose 的修改: cd ~/.nebula-up/nebula-docker-compose vim docker-compose.yaml # 参考附录一 docker network create nebula-net # 需要创建外部网络 docker-compose up -d --remove-orphans 之后,我们来创建要测试的图空间,并创建图的 Schema,为此,我们可以利用 nebula-console ,同样,Nebula-Up 里自带了容器化的 nebula-console。 进入 Nebula-Console 所在的容器 ~/.nebula-up/console.sh / # 在 console 容器里发起链接到图数据库,其中 192.168.x.y 是我所在的 Linux VM 的第一个网卡地址,请换成您的 / # nebula-console -addr 192.168.x.y -port 9669 -user root -p password [INFO] connection pool is initialized successfully Welcome to Nebula Graph! 创建图空间(我们起名字叫 sst ),以及 schema create space sst(partition_num=5,replica_factor=1,vid_type=fixed_string(32)); :sleep 20 use sst create tag player(name string, age int); 示例输出 (root@nebula) [(none)]> create space sst(partition_num=5,replica_factor=1,vid_type=fixed_string(32)); Execution succeeded (time spent 1468/1918 us) (root@nebula) [(none)]> :sleep 20 (root@nebula) [(none)]> use sst Execution succeeded (time spent 1253/1566 us) Wed, 18 Aug 2021 08:18:13 UTC (root@nebula) [sst]> create tag player(name string, age int); Execution succeeded (time spent 1312/1735 us) Wed, 18 Aug 2021 08:18:23 UTC 2. 搭建容器化的 Spark 环境 利用 big data europe 做的工作,这个过程非常容易。 值得注意的是: 现在的 Nebula Exchange 对 Spark 的版本有要求,在现在的 2021 年 8 月,我是用了 spark-2.4.5-hadoop-2.7 的版本。 为了方便,我让 Spark 运行在 Nebula Graph 相同的机器上,并且指定了运行在同一个 Docker 网络下 docker run --name spark-master --network nebula-net \ -h spark-master -e ENABLE_INIT_DAEMON=false -d \ bde2020/spark-master:2.4.5-hadoop2.7 然后,我们就可以进入到环境中了: docker exec -it spark-master bash 进到 Spark 容器中之后,可以像这样安装 maven: export MAVEN_VERSION=3.5.4 export MAVEN_HOME=/usr/lib/mvn export PATH=$MAVEN_HOME/bin:$PATH wget http://archive.apache.org/dist/maven/maven-3/$MAVEN_VERSION/binaries/apache-maven-$MAVEN_VERSION-bin.tar.gz && \ tar -zxvf apache-maven-$MAVEN_VERSION-bin.tar.gz && \ rm apache-maven-$MAVEN_VERSION-bin.tar.gz && \ mv apache-maven-$MAVEN_VERSION /usr/lib/mvn 还可以这样在容器里下载 nebula-exchange 的 jar 包: cd ~ wget https://repo1.maven.org/maven2/com/vesoft/nebula-exchange/2.1.0/nebula-exchange-2.1.0.jar 3. 搭建容器化的 HDFS 同样借助 big-data-euroupe 的工作,这非常简单,不过我们要做一点修改,让它的 docker-compose.yml 文件里使用 nebula-net 这个之前创建的 Docker 网络。 详细修改的部分参考附录二 git clone https://github.com/big-data-europe/docker-hadoop.git cd docker-hadoop vim docker-compose.yml docker-compose up -d 配置 Exchange 这个配置主要填入的信息就是 Nebula Graph 集群本身和将要写入数据的 Space Name,以及数据源相关的配置(这里我们用 csv 作为例子),最后再配置输出(sink)为 sst Nebula Graph GraphD 地址 MetaD 地址 credential Space Name 数据源 source: csv path fields etc. ink: sst 详细的配置参考附录二 注意,这里 metaD 的地址可以这样获取,可以看到 0.0.0.0:49377->9559 表示 49377 是外部的地址。 $ docker ps | grep meta 887740c15750 vesoft/nebula-metad:v2.0.0 "./bin/nebula-metad …" 6 hours ago Up 6 hours (healthy) 9560/tcp, 0.0.0.0:49377->9559/tcp, :::49377->9559/tcp, 0.0.0.0:49376->19559/tcp, :::49376->19559/tcp, 0.0.0.0:49375->19560/tcp, :::49375->19560/tcp nebula-docker-compose_metad0_1 生成 SST 文件 1. 准备源文件、配置文件 docker cp exchange-sst.conf spark-master:/root/ docker cp player.csv spark-master:/root/ 其中 player.csv 的例子: 1100,Tim Duncan,42 1101,Tony Parker,36 1102,LaMarcus Aldridge,33 1103,Rudy Gay,32 1104,Marco Belinelli,32 1105,Danny Green,31 1106,Kyle Anderson,25 1107,Aron Baynes,32 1108,Boris Diaw,36 1109,Tiago Splitter,34 1110,Cory Joseph,27 1111,David West,38 2. 执行 exchange 程序 进入 spark-master 容器,提交执行 exchange 应用。 docker exec -it spark-master bash cd /root/ /spark/bin/spark-submit --master local \ --class com.vesoft.nebula.exchange.Exchange nebula-exchange-2.1.0.jar\ -c exchange-sst.conf 检查执行结果: spark-submit 输出: 21/08/17 03:37:43 INFO TaskSetManager: Finished task 31.0 in stage 2.0 (TID 33) in 1093 ms on localhost (executor driver) (32/32) 21/08/17 03:37:43 INFO TaskSchedulerImpl: Removed TaskSet 2.0, whose tasks have all completed, from pool 21/08/17 03:37:43 INFO DAGScheduler: ResultStage 2 (foreachPartition at VerticesProcessor.scala:179) finished in 22.336 s 21/08/17 03:37:43 INFO DAGScheduler: Job 1 finished: foreachPartition at VerticesProcessor.scala:179, took 22.500639 s 21/08/17 03:37:43 INFO Exchange$: SST-Import: failure.player: 0 21/08/17 03:37:43 WARN Exchange$: Edge is not defined 21/08/17 03:37:43 INFO SparkUI: Stopped Spark web UI at http://spark-master:4040 21/08/17 03:37:43 INFO MapOutputTrackerMasterEndpoint: MapOutputTrackerMasterEndpoint stopped! 验证 HDFS 上生成的 SST 文件: docker exec -it namenode /bin/bash root@2db58903fb53:/# hdfs dfs -ls /sst Found 10 items drwxr-xr-x - root supergroup 0 2021-08-17 03:37 /sst/1 drwxr-xr-x - root supergroup 0 2021-08-17 03:37 /sst/10 drwxr-xr-x - root supergroup 0 2021-08-17 03:37 /sst/2 drwxr-xr-x - root supergroup 0 2021-08-17 03:37 /sst/3 drwxr-xr-x - root supergroup 0 2021-08-17 03:37 /sst/4 drwxr-xr-x - root supergroup 0 2021-08-17 03:37 /sst/5 drwxr-xr-x - root supergroup 0 2021-08-17 03:37 /sst/6 drwxr-xr-x - root supergroup 0 2021-08-17 03:37 /sst/7 drwxr-xr-x - root supergroup 0 2021-08-17 03:37 /sst/8 drwxr-xr-x - root supergroup 0 2021-08-17 03:37 /sst/9 写入 SST 到 Nebula Graph 这里的操作实际上都是参考文档:SST 导入,得来。其中就是从 console 之中执行了两步操作: Download Ingest 其中 Download 实际上是触发 Nebula Graph 从服务端发起 HDFS Client 的 download,获取 HDFS 上的 SST 文件,然后放到 storageD 能访问的本地路径下,这里,需要我们在服务端部署 HDFS 的依赖。因为我们是最小实践,我就偷懒手动做了这个 Download 的操作。 1. 手动下载 这里边手动下载我们就要知道 Nebula Graph 服务端下载的路径,实际上是 /data/storage/nebula/<space_id>/download/,这里的 Space ID 需要手动获取一下: 这个例子里,我们的 Space Name 是 sst,而 Space ID 是 49。 (root@nebula) [sst]> DESC space sst +----+-------+------------------+----------------+---------+------------+--------------------+-------------+-----------+ | ID | Name | Partition Number | Replica Factor | Charset | Collate | Vid Type | Atomic Edge | Group | +----+-------+------------------+----------------+---------+------------+--------------------+-------------+-----------+ | 49 | "sst" | 10 | 1 | "utf8" | "utf8_bin" | "FIXED_STRING(32)" | "false" | "default" | +----+-------+------------------+----------------+---------+------------+--------------------+-------------+-----------+ 于是,下边的操作就是手动把 SST 文件从 HDFS 之中 get 下来,再拷贝到 storageD 之中。 docker exec -it namenode /bin/bash $ hdfs dfs -get /sst /sst exit docker cp namenode:/sst . docker exec -it nebula-docker-compose_storaged0_1 mkdir -p /data/storage/nebula/49/download/ docker exec -it nebula-docker-compose_storaged1_1 mkdir -p /data/storage/nebula/49/download/ docker exec -it nebula-docker-compose_storaged2_1 mkdir -p /data/storage/nebula/49/download/ docker cp sst nebula-docker-compose_storaged0_1:/data/storage/nebula/49/download/ docker cp sst nebula-docker-compose_storaged1_1:/data/storage/nebula/49/download/ docker cp sst nebula-docker-compose_storaged2_1:/data/storage/nebula/49/download/ 2. SST 文件导入 进入 Nebula-Console 所在的容器 ~/.nebula-up/console.sh / # 在 console 容器里发起链接到图数据库,其中 192.168.x.y 是我所在的 Linux VM 的第一个网卡地址,请换成您的 / # nebula-console -addr 192.168.x.y -port 9669 -user root -p password [INFO] connection pool is initialized successfully Welcome to Nebula Graph! 执行 INGEST 开始让 StorageD 读取 SST 文件 (root@nebula) [(none)]> use sst (root@nebula) [sst]> INGEST; 我们可以用如下方法实时查看 Nebula Graph 服务端的日志 tail -f ~/.nebula-up/nebula-docker-compose/logs/*/* 成功的 INGEST 日志: I0817 08:03:28.611877 169 EventListner.h:96] Ingest external SST file: column family default, the external file path /data/storage/nebula/49/download/8/8-6.sst, the internal file path /data/storage/nebula/49/data/000023.sst, the properties of the table: # data blocks=1; # entries=1; # deletions=0; # merge operands=0; # range deletions=0; raw key size=48; raw average key size=48.000000; raw value size=40; raw average value size=40.000000; data block size=75; index block size (user-key? 0, delta-value? 0)=66; filter block size=0; (estimated) table size=141; filter policy name=N/A; prefix extractor name=nullptr; column family ID=N/A; column family name=N/A; comparator name=leveldb.BytewiseComparator; merge operator name=nullptr; property collectors names=[]; SST file compression algo=Snappy; SST file compression options=window_bits=-14; level=32767; strategy=0; max_dict_bytes=0; zstd_max_train_bytes=0; enabled=0; ; creation time=0; time stamp of earliest key=0; file creation time=0; E0817 08:03:28.611912 169 StorageHttpIngestHandler.cpp:63] SSTFile ingest successfully 附录 附录一 docker-compose.yaml diff --git a/docker-compose.yaml b/docker-compose.yaml index 48854de..cfeaedb 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -6,11 +6,13 @@ services: USER: root TZ: "${TZ}" command: - - --meta_server_addrs=metad0:9559,metad1:9559,metad2:9559 + - --meta_server_addrs=metad0:9559 - --local_ip=metad0 - --ws_ip=metad0 - --port=9559 - --ws_http_port=19559 + - --ws_storage_http_port=19779 - --data_path=/data/meta - --log_dir=/logs - --v=0 @@ -34,81 +36,14 @@ services: cap_add: - SYS_PTRACE - metad1: - image: vesoft/nebula-metad:v2.0.0 - environment: - USER: root - TZ: "${TZ}" - command: - - --meta_server_addrs=metad0:9559,metad1:9559,metad2:9559 - - --local_ip=metad1 - - --ws_ip=metad1 - - --port=9559 - - --ws_http_port=19559 - - --data_path=/data/meta - - --log_dir=/logs - - --v=0 - - --minloglevel=0 - healthcheck: - test: ["CMD", "curl", "-sf", "http://metad1:19559/status"] - interval: 30s - timeout: 10s - retries: 3 - start_period: 20s - ports: - - 9559 - - 19559 - - 19560 - volumes: - - ./data/meta1:/data/meta - - ./logs/meta1:/logs - networks: - - nebula-net - restart: on-failure - cap_add: - - SYS_PTRACE - - metad2: - image: vesoft/nebula-metad:v2.0.0 - environment: - USER: root - TZ: "${TZ}" - command: - - --meta_server_addrs=metad0:9559,metad1:9559,metad2:9559 - - --local_ip=metad2 - - --ws_ip=metad2 - - --port=9559 - - --ws_http_port=19559 - - --data_path=/data/meta - - --log_dir=/logs - - --v=0 - - --minloglevel=0 - healthcheck: - test: ["CMD", "curl", "-sf", "http://metad2:19559/status"] - interval: 30s - timeout: 10s - retries: 3 - start_period: 20s - ports: - - 9559 - - 19559 - - 19560 - volumes: - - ./data/meta2:/data/meta - - ./logs/meta2:/logs - networks: - - nebula-net - restart: on-failure - cap_add: - - SYS_PTRACE - storaged0: image: vesoft/nebula-storaged:v2.0.0 environment: USER: root TZ: "${TZ}" command: - - --meta_server_addrs=metad0:9559,metad1:9559,metad2:9559 + - --meta_server_addrs=metad0:9559 - --local_ip=storaged0 - --ws_ip=storaged0 - --port=9779 @@ -119,8 +54,8 @@ services: - --minloglevel=0 depends_on: - metad0 - - metad1 - - metad2 healthcheck: test: ["CMD", "curl", "-sf", "http://storaged0:19779/status"] interval: 30s @@ -146,7 +81,7 @@ services: USER: root TZ: "${TZ}" command: - - --meta_server_addrs=metad0:9559,metad1:9559,metad2:9559 + - --meta_server_addrs=metad0:9559 - --local_ip=storaged1 - --ws_ip=storaged1 - --port=9779 @@ -157,8 +92,8 @@ services: - --minloglevel=0 depends_on: - metad0 - - metad1 - - metad2 healthcheck: test: ["CMD", "curl", "-sf", "http://storaged1:19779/status"] interval: 30s @@ -184,7 +119,7 @@ services: USER: root TZ: "${TZ}" command: - - --meta_server_addrs=metad0:9559,metad1:9559,metad2:9559 + - --meta_server_addrs=metad0:9559 - --local_ip=storaged2 - --ws_ip=storaged2 - --port=9779 @@ -195,8 +130,8 @@ services: - --minloglevel=0 depends_on: - metad0 - - metad1 - - metad2 healthcheck: test: ["CMD", "curl", "-sf", "http://storaged2:19779/status"] interval: 30s @@ -222,17 +157,19 @@ services: USER: root TZ: "${TZ}" command: - - --meta_server_addrs=metad0:9559,metad1:9559,metad2:9559 + - --meta_server_addrs=metad0:9559 - --port=9669 - --ws_ip=graphd - --ws_http_port=19669 + - --ws_meta_http_port=19559 - --log_dir=/logs - --v=0 - --minloglevel=0 depends_on: - metad0 - - metad1 - - metad2 healthcheck: test: ["CMD", "curl", "-sf", "http://graphd:19669/status"] interval: 30s @@ -257,17 +194,19 @@ services: USER: root TZ: "${TZ}" command: - - --meta_server_addrs=metad0:9559,metad1:9559,metad2:9559 + - --meta_server_addrs=metad0:9559 - --port=9669 - --ws_ip=graphd1 - --ws_http_port=19669 + - --ws_meta_http_port=19559 - --log_dir=/logs - --v=0 - --minloglevel=0 depends_on: - metad0 - - metad1 - - metad2 healthcheck: test: ["CMD", "curl", "-sf", "http://graphd1:19669/status"] interval: 30s @@ -292,17 +231,21 @@ services: USER: root TZ: "${TZ}" command: - - --meta_server_addrs=metad0:9559,metad1:9559,metad2:9559 + - --meta_server_addrs=metad0:9559 - --port=9669 - --ws_ip=graphd2 - --ws_http_port=19669 + - --ws_meta_http_port=19559 - --log_dir=/logs - --v=0 - --minloglevel=0 + - --storage_client_timeout_ms=60000 + - --local_config=true depends_on: - metad0 - - metad1 - - metad2 healthcheck: test: ["CMD", "curl", "-sf", "http://graphd2:19669/status"] interval: 30s @@ -323,3 +266,4 @@ services: networks: nebula-net: + external: true 附录二 https://github.com/big-data-europe/docker-hadoop 的 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml index ed40dc6..66ff1f4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,6 +14,8 @@ services: - CLUSTER_NAME=test env_file: - ./hadoop.env + networks: + - nebula-net datanode: image: bde2020/hadoop-datanode:2.0.0-hadoop3.2.1-java8 @@ -25,6 +27,8 @@ services: SERVICE_PRECONDITION: "namenode:9870" env_file: - ./hadoop.env + networks: + - nebula-net resourcemanager: image: bde2020/hadoop-resourcemanager:2.0.0-hadoop3.2.1-java8 @@ -34,6 +38,8 @@ services: SERVICE_PRECONDITION: "namenode:9000 namenode:9870 datanode:9864" env_file: - ./hadoop.env + networks: + - nebula-net nodemanager1: image: bde2020/hadoop-nodemanager:2.0.0-hadoop3.2.1-java8 @@ -43,6 +49,8 @@ services: SERVICE_PRECONDITION: "namenode:9000 namenode:9870 datanode:9864 resourcemanager:8088" env_file: - ./hadoop.env + networks: + - nebula-net historyserver: image: bde2020/hadoop-historyserver:2.0.0-hadoop3.2.1-java8 @@ -54,8 +62,14 @@ services: - hadoop_historyserver:/hadoop/yarn/timeline env_file: - ./hadoop.env + networks: + - nebula-net volumes: hadoop_namenode: hadoop_datanode: hadoop_historyserver: + +networks: + nebula-net: + external: true 附录三 nebula-exchange-sst.conf { # Spark relation config spark: { app: { name: Nebula Exchange 2.1 } master:local driver: { cores: 1 maxResultSize: 1G } executor: { memory:1G } cores:{ max: 16 } } # Nebula Graph relation config nebula: { address:{ graph:["192.168.8.128:9669"] meta:["192.168.8.128:49377"] } user: root pswd: nebula space: sst # parameters for SST import, not required path:{ local:"/tmp" remote:"/sst" hdfs.namenode: "hdfs://192.168.8.128:9000" } # nebula client connection parameters connection { # socket connect & execute timeout, unit: millisecond timeout: 30000 } error: { # max number of failures, if the number of failures is bigger than max, then exit the application. max: 32 # failed import job will be recorded in output path output: /tmp/errors } # use google's RateLimiter to limit the requests send to NebulaGraph rate: { # the stable throughput of RateLimiter limit: 1024 # Acquires a permit from RateLimiter, unit: MILLISECONDS # if it can't be obtained within the specified timeout, then give up the request. timeout: 1000 } } # Processing tags # There are tag config examples for different dataSources. tags: [ # HDFS csv # Import mode is sst, just change type.sink to client if you want to use client import mode. { name: player type: { source: csv sink: sst } path: "file:///root/player.csv" # if your csv file has no header, then use _c0,_c1,_c2,.. to indicate fields fields: [_c1, _c2] nebula.fields: [name, age] vertex: { field:_c0 } separator: "," header: false batch: 256 partition: 32 } ] } 本文中如有任何错误或疏漏,欢迎去 GitHub:https://github.com/vesoft-inc/nebula issue 区向我们提 issue 或者前往官方论坛:https://discuss.nebula-graph.com.cn/ 的 建议反馈 分类下提建议 👏;交流图数据库技术?加入 Nebula 交流群请先填写下你的 Nebula 名片,Nebula 小助手会拉你进群~~

优秀的个人博客,低调大师

服务器框架 Serverless 发布 2.65.0 版本

Serverless发布了 2.65.0版本,该框架使用 AWS Lambda、Azure Functions、Google CloudFunctions 等技术,可以构建 Serverless 架构的 Web、移动和 IoT 应用。 特性 AWS Lambda: 为functions[].reservedConcurrency添加 CF 内在函数支持。(#10129) 允许使用lambdaHashingVersion: 20200924设置来维持当前默认的 Lambda 哈希版本模式。(#10173) AWS EventBridge:仍然可以对 EventBridge 资源使用基于自定义资源的部署方法。(#10133) AWS Local Invocation:支持 Python 十进制序列化。(#10178) Bug修复 AWS Deploy:修复对部署存储桶扩展的处理。 (#10137) AWS HTTP API:将最大超时时间识别为 30 秒,而不是 29 秒。(#10119) 命令行界面: 修复help命令的使用信息 。 (#10175) 修复未集成命令的帮助解析 。(#10128) 在验证错误时,自动识别可访问的配置部分。(#10134) 性能改进 CLI:集成 CLI 分流到包中(没有@serverless/components和@serverless/cli模块,除非使用它们的 CLI)(#10131) 。 维护改进 命令行界面: 改进日志的文件大小输出。 (#10169) 改进主要进度的消息。 (#10183) 遥测:添加projectId到有效载荷。 (#10180) AWS EventBridge:修复错误消息的拼写错误。 (#10165) 分离内部和插件输出部分。 (#10184) 模板 在aws-nodejs-typescript中单独打包 lambda 。(#10106) 升级azure-nodejs-typescript。(#10163) 更新公告:https://github.com/serverless/serverless/releases/tag/v2.65.0

优秀的个人博客,低调大师

Phalcon+Swoole 侵入解决方案 PhaService

Phalcon有着强大的性能同时又具备完整的MVC模式, Swoole也具备在Phalcon之外的其他能力,如果把两者无缝的结合, 一定是一个不错的案例. 所以本项目 同时支持 Nginx+Phalcon 与 Swoole+Phalcon, 如果使用Nginx做负载均衡,可以做到无缝衔接,有Nginx+php-fpm的稳定, 同时也能享受Swoole对于API的超高性能. 本案例可以作为系统服务使用, 也可以做Restful开发使用,作为Web使用更是毫无问题. 使用 wrk 做的的压测, 在MBP上的结果: wrk -c10000 -d10s --latency http://127.0.0.1:8080/testRunning 10s test @ http://127.0.0.1:8080/test 2 threads and 10000 connections Thread Stats Avg Stdev Max +/- Stdev Latency 38.66ms 50.01ms 266.35ms 81.83% Req/Sec 12.97k 1.54k 16.65k 88.17% Latency Distribution 50% 11.53ms 75% 68.33ms 90% 116.48ms 99% 183.72ms 242375 requests in 10.06s, 36.59MB read Requests/sec: 24104.01 Transfer/sec: 3.64MB 非常不错的结果. Installation ** Web服务兼容Nginx+PHP-FPM模式,可以参考Phalcon的Nginx配置. 依赖: Ubuntu 16.04LTS/18.04LTS PHP: 7.0+, 推荐 7.2或以上 Beantalkd 队列处理依赖 php扩展 Phalcon 3.x+ php扩展 Swoole 2.x+ php扩展 Redis php扩展 Pdo,Pdo MySQL ####初始化 composer install -o 开启 HttpServer 服务:建议使用Nginx做负载均衡,使PHP-FPM可以和Swoole的HttpServer同时提供服务. ./web_serve start 可以使用sys/systemd/StdWebServer.GenService.php可以生成systemd service文件, 根据提示安装成服务. cd sys/systemd/ php StdWebServer.GenService.php 开启 WebSocketServer 服务: ./web_socket_serve start 可以使用sys/systemd/StdWebSocketServer.GenService.php可以生成systemd service文件, 根据提示安装成服务. cd sys/systemd/ php StdWebSocketServer.GenService.php Configuration 环境配置 在项目的/目录下,建立空文件.development或.testing则指定里开发环境与测试环境, 没有文件为生产环境. 文件同时存在, 有限开启开发环境. #开发环境 rm .testing && touch .development #测试环境 rm .development && touch .testing #生产环境 rm .development .testing 数据库,Redis等配置: Web与Cli分开配置,配置文件位于: App部分:/app/config/config.php Cli部分:/cli/config/config.php Swoole Http Server 配置: 配置文件:/sys/config/std_web_server.php Swoole WebSocket Server 配置: 配置文件:/sys/config/std_web_socket_server.php Features Phalcon 完整支持 Http 服务器 WebSocket 服务器 多进程Task Worker 任务处理 Beantalk 队列 Systemd自启服务 Documents ###多进程Task任务处理 该服务会在任务处理完成后,持续拉起服务,所以可以实现类似php-fpm的特点, 任务处理指定次数后退出任务,服务会自动拉起服务. 具体可以参考/cli/tasks/MailSenderTask.php, 复写 RealWork 函数进行真实的任务处理即可, 调用方式: #查看帮助信息 ./run mailsender -h #参数 6 为开启6个子进程同时处理任务 ./run mailsender 6 本文来自云栖社区合作伙伴“开源中国” 本文作者:局长 原文链接

优秀的个人博客,低调大师

惧失败,Docker EE 帮助企业快速试错

本文首发自“Docker公司”公众号(ID:docker-cn)编译丨小东每周一、三、五 与您不见不散! 当您想要将公司进行抵押贷款时,您首先想到是有很多文书工作需要处理,而且整个过程会非常的漫长、繁琐。但是 Franklin American Mortgage Company 却想要这种突破传统模式。通过对创新、微服务和 Docker EE 等技术的投入,他们正在迅速创建一个平台,让技术核心帮助他们取得成功。 Franklin American 公司的 DevOps 负责人 Don Bauer 是该公司去年成立的一个创新型团队中的一员。Franklin American 公司正在做一件了不起的事情 —— 以 Docker EE 为基础一步步的对其业务进行变革。 Don Bauer 与 Franklin American 公司的创新部副总裁 Sharon Frazier 一同在 DockerCon 2018 大会上发表演讲。他们能够凭借四大支柱快速构建 DevOps 文化:即可视化、简单化、标准化和实验法。其中实验法是关键,它可以帮助他们无后顾之忧地进行快速试错。 DevOps 负责人 Don Bauer 表示:“Docker 让我们不惧失败,我们可以轻松、快速地对新事物进行测试,如果它适合我们,那我们就成功了。如果它不适合我们,那我们也无需为它浪费数周或数月的时间!。” 对于公司来说,创新不仅仅在于新技术的产生,更多的是为客户做一些新的、相关的事情。团队想要解决的第一个难题就是公司在定价方面的竞争地位。设置和锁定抵押贷款定价的“锁定引擎”是维持公司竞争力的关键。 Docker EE 让 Franklin American 公司在改革的进程中走得更快。 创新部副总裁 Sharon Frazier 表示“我认为我们迄今为止最大的成功就是我们能够在短短的一周内将一个想法从头到尾的实现。我们意识这是一个机会并且牢牢地抓住了这个机会。” 如今,公司拥有一个40个节点的集群以支持开发、测试、QA和生产环节,并且每个环节都有着各自独立的环境。它们运行着20个环境和超过300个由1,000个容器支持的服务。 更令人印象深刻的是,他们的动作非常快。正如 Don 和 Sharon 在他们的 DockerCon 演讲中所分享的那样,自2017年11月17日以来,Franklin American 公司的 DevOps 团队已经完成了超过10,000次的部署,平均每天部署200次,有时甚至更多。 正如 Sharon 在 DockerCon 上所说的那样,她自己正在美国企业内部进行“创业”,这无疑是全球最好的工作。与 Docker 合作,创新团队可以确保公司在未来的10年内保持相关性和竞争力。 想要了解关于 Franklin American 公司的更多信息,请从以下渠道观看他们的 DockerCon 2018 演讲视频: Docker官方微信公众号入口:http://t.cn/RrT7xxo

优秀的个人博客,低调大师

Skype再升级 同时25人通话压力

提到视频和语音通话软件,我们最先会想到腾讯的QQ和微信,但其实微软的Skype也是一款不错的软件。在自家平台升级之后,近日微软也为iOS和Android版的Skype进行了功能上的升级升级。 据悉,全新的Skype群组视频通话功能最多支持25人同时在线,通过与英特尔的合作,利用SILK Super Wide Band技术通过英特尔处理器在云端解码Azure编码,以达到同时处理器如此高要求的通话需求。 除了群视频功能之外,微软还提升了iOS和Android版的邀请聊天功能,用户可以要求任何好友进行群组通话,甚至包括视频功能。 本文转自d1net(转载)

优秀的个人博客,低调大师

常用省市区刷新联动实例

1、jquery代码 function getCity(CityVal) { var DDL_Province = $("#DDL_Province"); var DDL_City = $("#DDL_City"); DDL_City.empty(); DDL_City.append("<option value=\"0\">市/区</option>"); $.ajax( { type: "post", url: "/UserCart/Controller/CityAreas.ashx", data: { "type": "city", "provinceID": DDL_Province.val() }, dataType: "json", async: false, success: function (msg) { for (var i = 0; i < msg.length; i++) { if (CityVal == msg[i].CityName) { if (msg[i].IsCOD == 1) { DDL_City.append("<option value=" + msg[i].CityID + " selected=\"selected\">" + msg[i].CityName + "*</option>"); } else { DDL_City.append("<option value=" + msg[i].CityID + " selected=\"selected\">" + msg[i].CityName + "</option>"); } } else { if (msg[i].IsCOD == 1) { DDL_City.append("<option value=" + msg[i].CityID + " >" + msg[i].CityName + "*</option>"); } else { DDL_City.append("<option value=" + msg[i].CityID + " >" + msg[i].CityName + "</option>"); } } } getArea(''); GetAddreesSpan(); } }) }; function getArea(AreaVal) { var DDL_City = $("#DDL_City"); var DDL_Area = $("#DDL_Area"); DDL_Area.empty(); DDL_Area.append("<option value=\"0\">县/乡</option>"); $.ajax( { type: "post", url: "/UserCart/Controller/CityAreas.ashx", data: { "type": "district", "cityID": DDL_City.val() }, dataType: "json", async: false, success: function (msg) { for (var i = 0; i < msg.length; i++) { if (AreaVal == msg[i].DistrictName) { if (msg[i].IsCOD == 1) { DDL_Area.append("<option value=" + msg[i].DistrictID + " selected=\"selected\">" + msg[i].DistrictName + "*</option>"); } else { DDL_Area.append("<option value=" + msg[i].DistrictID + " selected=\"selected\">" + msg[i].DistrictName + "</option>"); } } else { if (msg[i].IsCOD == 1) { DDL_Area.append("<option value=" + msg[i].DistrictID + " >" + msg[i].DistrictName + "*</option>"); } else { DDL_Area.append("<option value=" + msg[i].DistrictID + " >" + msg[i].DistrictName + "</option>"); } } } GetAddreesSpan(); } }) }; function GetAddreesSpan() { } 2、后端C#代码 <%@ WebHandler Language="C#" Class="CityAreas" %> using System; using System.Web; using System.Collections.Generic; public class CityAreas : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; if (context.Request["type"] == "city") { context.Response.Write(select2(context.Request["provinceID"])); } else if (context.Request["type"] == "district") { context.Response.Write(select3(context.Request["cityID"])); } } public string select2(string id) { string str = string.Empty; if (!string.IsNullOrEmpty(id)) { List<ECS.Model.A_CityAreas> list = new ECS.BLL.A_CityAreas().GetList(null, "deep=2 and ParentID=" + id, null); if (list != null && list.Count > 0) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("["); foreach (ECS.Model.A_CityAreas item in list) { sb.Append("{"); sb.Append("\"CityID\":\"" + item.id + "\",\"CityName\":\"" + item.AreaName + "\",\"IsCOD\":\"" + item.IsCOD + "\""); sb.Append("},"); } sb.Remove(sb.Length - 1, 1); sb.Append("]"); str = sb.ToString(); } } return str; } public string select3(string id) { string str = string.Empty; if (!string.IsNullOrEmpty(id)) { List<ECS.Model.A_CityAreas> list = new ECS.BLL.A_CityAreas().GetList(null, "deep=3 and ParentID=" + id, null); if (list != null && list.Count > 0) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("["); foreach (ECS.Model.A_CityAreas item in list) { sb.Append("{"); sb.Append("\"DistrictID\":\"" + item.id + "\",\"DistrictName\":\"" + item.AreaName + "\",\"IsCOD\":\"" + item.IsCOD + "\""); sb.Append("},"); } sb.Remove(sb.Length - 1, 1); sb.Append("]"); str = sb.ToString(); } } return str; } public bool IsReusable { get { return false; } } }

资源下载

更多资源
Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册