Git Product home page Git Product logo

013_load_balancer's Introduction

说明

编写简单的负载均衡器,功能:

  • 轮询分发
  • 失败重试
  • 后端可用性检测

这个代码仓库包含两个项目,一个是后端服务项目,可以通过设置端口来启动多个服务器,模拟负载均衡器后端的多台服务器。第二个是 main.go 里的负载均衡器。

视频链接

运行代码

go run .

后端服务

启动后端服务:

go run backend/myapp.go -port=6000 > /dev/null 2>&1 &
go run backend/myapp.go -port=6001 > /dev/null 2>&1 &
go run backend/myapp.go -port=6002 > /dev/null 2>&1 &
go run backend/myapp.go -port=6003 > /dev/null 2>&1 &
go run backend/myapp.go -port=6004 > /dev/null 2>&1 &

停止所有后端服务:

kill -9 $(lsof -t -i:6000,6001,6002,6003,6004 -sTCP:LISTEN)

停止单个后端:

kill -9 $(lsof -t -i:6004 -sTCP:LISTEN)

批量发送 CURL 请求:

for n in {1..10}; do curl http://localhost:8000; done

013_load_balancer's People

Contributors

summerblue avatar

Stargazers

Alfred avatar JeffreyBool avatar JellyTony avatar 梁达标 avatar y12m09x avatar Byte avatar 万欢喜 avatar  avatar Sion avatar 07 avatar

Watchers

 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.