27 Star 75 Fork 12

白_猫 / SwooleDistributed

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

SD3.X

支持swoole2,采用内置协程,摆脱yield。

完善的教学文档:https://www.kancloud.cn/tmtbe/sd3

丰富的高级功能

创新的Actor模型

SwooleDistributed

今年年底历时2年多的迭代,这是SD框架硕果满满的一年,通过不断的迭代和改进SD框架已经在圈内有良好的口碑,不少新生的框架借鉴了SD的设计思想,SD框架也被不少创业型公司和大型企业使用。

SD框架到底是什么技术

SD框架全称SwooleDistributed,从名称上看一个是Swoole一个是Distributed,他是基于Swoole扩展的可以分布式部署的应用服务器框架。 借助于PHP的高效开发环境,Swoole的高性能异步网络通信引擎,以及其他的高可用的扩展和工具,SD框架提供给广大开发者一个稳定的高效的而且功能强大的应用服务器框架。

入门成本

老实的说相对比目前热门的FPM框架来说,SD的入门成本相对还是比较高的,因为设计理念不同以及和传统PHP-FPM环境完全不同的运行环境,对于长时间使用LAMP(LANP)技术的开发人员来说会有一段时间的适应期,如果开发应用简单涉及到的系统复杂度低,那么SD上手还是比较容易,根据简单的例子和文档几乎立即就能开启SD的探索之旅,但是如果开发的是复杂的应用那么SD包含的众多组件还是需要你慢慢熟悉上手的。

SD框架到底包含哪些强大的功能呢

我们这里列举下SD提供的各种各样的功能以及模块组件

  • 混合协议 SD框架支持长连接协议TCP,WebSocket,短连接协议HTTP,以及UDP。 通过配置开放不同的端口开发者可以轻松管理不同的协议,并且可以共用一套业务代码,当然你可以通过智能路由进行代码的隔离。 长连接可以配置不同的数据传输协议,比如二进制协议文本协议等等,通过框架提供的封装器解包器接口可以自定义各种各种的协议封装,并且各种协议之间可以自动转换,比如你通过广播发送一个信息,该信息流向不同客户端,客户端间采用不同协议,那么框架会根据不同的端口自动转换不同的协议封装。 你也可以通过Http给所有长连接客户端发送推送消息,类似这种混合协议协作的业务在SD框架上会异常简单。
  • MVC以及智能路由 框架的设计是MVC架构,其中每一个层级都可以继续划分子层级,开发者可以将Controller继续分层通过不同文件夹进行管理,也可以将Model进行细分,划分为业务层和数据层,这都看开发者自身的系统设计。智能路由将处理解包器解包后的数据,负责将这些数据传递到Controller层。
  • 中间件 SD框架还提供了中间件,中间件可以对流入的数据进行处理,比如清理异常数据,修改数据,流量统计,搜集日志等功能。中间件可以设置多个,他们和端口进行绑定。
  • 对象池 SD框架内大多数的对象都使用了对象池技术,对象池技术有利于系统内存的稳定,减少GC的次数,提高系统的运行效率,事实证明对象池对系统稳定做出了极大的贡献,开发者也可以使用这一套对象池技术,增加对对象的复用,减少GC和NEW的频率,对系统毛刺现象和内存泄露方面都有很大的稳定性提升。
  • 异步客户端以及连接池 Mysql,Redis,Http客户端,Tcp客户端,等等其他更为复杂的客户端,在SD框架中均为异步的模式,异步解决了系统整体的并发能力,但异步客户端需要提供连接池维持,SD框架提供了连接池,开发者不需要自己管理连接池,只需要使用即可。
  • 协程 异步事件回调解决的是并发性能,但造成的是业务代码的混乱。SD框架提供了协程解决了这一问题,通过yield关键字提供对异步的同步写法,消除了业务书写上的大量回调嵌套,你可以通过yield+同步的写法实现异步的性能。 协程提供了一整套完整的体系,包括超时,异常,休眠,多路选择,以及创建用户协程等等功能。
  • 定时任务 顾名思义定时执行的任务。
  • 任务投递 支持将耗时任务投递到Task进程。
  • 自动Reload 可以开启框架的自动Reload功能,这样代码修改会被立即响应。

上面描述的都是一些基础功能,大家开发应用时经常用到的,那么下面则是一些高级功能。

  • 集群以及微服务 框架提供集群部署,通过开启集群开关,部署Consul工具服务器,我们就可以开启集群之旅,框架中消息功能都是支持集群环境的。通过暴露API,监听API,我们可以实现微服务,微服务中我们又提供了健康监控,熔断,超时,负载均衡,请求迁移等等功能。 集群采用的是对等网络,没有中间节点,没有单点隐患,设计理念如下图所示。 image

  • 订阅与发布 SD提供的订阅发布功能也是支持集群环境,并且它严格的按照MQTT所定义的订阅发布规范,并且实现了所有的功能。这恐怕是最好最优秀的订阅发布功能了。

  • 事件派发 跨进程跨服务器的事件派发功能,很多SD框架的基础设施都是基于这个搭建的。

  • 用户进程管理以及进程间RPC SD框架重新封装了用户进程,开发者可以启动自己的用户进程,用户进程可以是异步的也可以是同步的,也是支持各种连接池和协程,用户进程的用处很多,同样框架也支持用户进程和Worker进程间互相RPC调用。

  • 集群下的定时任务 通过Consul可以设置定时任务,并且会同步到集群所有的服务器上去执行,集群服务器会选举出一个Leader,可以通过获取是否是Leader来决定这个任务是否被执行。

  • Context上下文 这个是在消息处理整个流程中被共享的上下文,很实用,很方便。

接下来介绍的是SD特色组件

  • 异步AMQP客户端以及分布式任务系统 消息队列协议AMQP,框架提供了一个支持AMQP协议的异步客户端,可以和RabbitMQ联动,通过框架提供的分布式任务组件,可以搭建分布式任务系统。
  • 异步MQTT客户端 异步的MQTT客户端可以和MQTT服务实现订阅与发布
  • MQTT简易集群服务器 支持QOS0级别的简易MQTT服务器,支持集群部署。
  • 服务器监控系统 提供了一个服务器监控后台,可以对集群进行监控,也可以监控某一台服务器的具体运行状况。 下面是一些截图

SD框架远远不止现在

SD框架一直在高速发展中,有更多开发者的参与才会有更好的未来。 附带SD框架的文档以及官网 官网 文档 GitHub 如果你喜欢,请打个星星支持下~

High performance, high concurrency, PHP asynchronous distributed framework,power by ext-swoole

Development communication QQ-group:569037921

Simple websocket case

Chat room: https://github.com/tmtbe/SD-todpole

Live Demo: http://114.55.253.83:8081/

The official website:http://sd.youwoxing.net

Development document:http://docs.youwoxing.net

Instructional video:http://v.qq.com/boke/gplay/337c9b150064b5e5bcfe344f11a106c5_m0i000801b66cfv.html

Install

You can install via composer

Autoload must specify app and test.

{
  "require": {
    "tmtbe/swooledistributed":">2.0.0"
  },
 "autoload": {
    "psr-4": {
      "app\\": "src/app",
      "test\\": "src/test"
    }
  }
}

Then execute the following code in the root directory (the vendor higher directory)

php vendor/tmtbe/swooledistributed/src/Install.php

The server can be executed in the bin at the end of the installation.

Advantage

1.High performance and high concurrency, asynchronous event driven

2.HttpClient, client, Mysql, Redis connection pooling

3.Timed task system

4.Coroutine Support

5.Using object pooling mode, optimizing memory allocation and GC

6.Many asynchronous clients, such as MQTT, AMQP, etc.

7.Support cluster deployment

8.User process management

9.Support multi port, multi protocol, automatic conversion between protocols

10.Micro service management based on Consul

11.Automatic discovery of cluster nodes based on Consul

12.Support pubish-subscribe mode

13.MQTT Server

14.Asynchronous operating system

Architecture diagram

Class inheritance structure

image

Process structure

image

Cluster structure

image

Donation

If you like the project, I hope you donate this project so that the project will get better development, Thank you.

Alipay:

image

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright Jincheng.Zhang [tmtbe@163.com] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

基于swoole的微服务框架,分布式系统,支持TCP/HTTP/WS,效率强劲,功能强大。 展开 收起
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
PHP
1
https://gitee.com/tmtbe/SwooleDistributed.git
git@gitee.com:tmtbe/SwooleDistributed.git
tmtbe
SwooleDistributed
SwooleDistributed
v2

搜索帮助