Giter Club home page Giter Club logo

wangscript007 / distributed-system-framework Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lexingsen/distributed-system-framework

0.0 0.0 0.0 1.22 MB

这是一个基于Linux平台,C++编写的分布式系统。服务器端采用了线程池+Libevent的IO模型,并为其实现了简单的负载均衡。服务器端业务层使用了MVC的设计模式。数据存储方面对MySQL数据库C-API进行了C++的类封装。为了实现服务器集群的负载均衡,实现了以一致性hash为底层算法的负载均衡服务器,这可以作为一个单独的模块。

C++ 46.70% Makefile 26.84% C 13.84% CMake 12.62%

distributed-system-framework's Introduction

分布式系统框架

一.项目简介

这是基于Linux平台C++编写的分布式系统框架,非常适合对Linux后端项目有需求的同学学习。
主要包含四个文件,分别是服务器端、客户端、负载均衡服务器端以及信息采集器。
涉及到的技术:

(1)Linux下socket编程, 封装TcpServer,TcpClient

(2)Libevent网络框架库的使用

(3)服务器端线程池的使用以及其负载均衡

(4)MySQL数据库C接口的C++类封装

(5)单例模式

(6)负载均衡算法之一致性hash算法

(7)CJson格式的消息封装

(8)MD5算法

二.项目工作流程

在具体谈整个项目的工作流程前,先来谈谈客户端到底是如何如服务器建立连接的。在未实现负载均衡服务器前,通常我们会为客户端指定服务器的ip地址和端口,直接连接。但是这样存在的问题是服务器当并发量大到一定的程度时,由于压力太大,出现对客户端响应过慢的情况,甚至可能会出现宕机的情况,

Image text

为了降低单个服务器的压力,我们可以将服务器进行集群式的管理,使用负载均衡服务器来监管集群服务器上每个服务器当前的压力,进行动态的管理。在这种情况下,客户端就需要先去连接负载均衡服务器,让其分配一个当前负载均衡服务器管理的服务器中压力最小的那个,将其ip地址和端口发送给客户端。客户端拿到负载均衡服务器分配给它的服务器的ip地址和端口后,客户端主动断开与负载均衡服务器的连接,转而去连接服务器。

Image text

现在我们来谈整个项目的部署及流程:

1.启动负均衡服务器主函数,并分别设置为服务器和客户端用于连接的socket。

Image text

2.启动MySQL数据库服务。

Image text

3.启动服务器主函数,首先连接负载均衡服务器,之后监听客户端的连接。

Image text

这里可以多连几个服务器到负载均衡服务器,便于观察,我们看负载均衡端的log输出。

Image text

4.启动客户端主函数

Image text

distributed-system-framework's People

Contributors

lexingsen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.