微信聊天tcp设计 tcp负载均衡模型
1:单体
1.1:点对点
两边公网ip:
缺点:
1.多少个好友就多少个公网tcp连接,手机资源消耗大
2.公网ip端口被封,即使wifi环境用nat也不是很好的方案
1.2:专门搞台服务器,暴露公网ip和端口
A、B登陆,保存channel <uid, channel>
A发送B消息,服务器取得B的channel,write
1.3:聊天室
<roomid, List<uid>>
<uid, channel>
https://mp.weixin.qq.com/s?__biz=MzUzMTA2NTU2Ng==&mid=2247484883&idx=1&sn=1a448b21d9fecd9fa4eeff2c51eed9b9&chksm=fa497a62cd3ef37480bd3d003d83d15b0ed6e6166f33c7d5d8484646299eb0979a6bc45cc7ef&mpshare=1&scene=1&srcid=08114vLIYxhRKmYoyf4U0bhP&key=ce0fa4dcd93707bbaaf8db0e48719082b0c76c1bf79933fb217690f7593ce2afd2f3b364b514cb98cb80d2a2578cfa09f064e9f60a87d16086fee24c846ee58ba299f62b78cc9b94cbdf944b5aba337c&ascene=0&uin=MTA2NzUxMDAyNQ%3D%3D&devicetype=iMac+MacBookAir6%2C2+OSX+OSX+10.10.5+build(14F2511)&version=11020012&lang=zh_CN&pass_ticket=PxWaGEWWe0eNv4G2j4iXpikni7NYO3V%2FsH0QQT%2FdQT2iUGUsChVqp%2BppkOxUDJNX
2:负载均衡
2.1:初始化
(1)配置后端服务器列表
(2)心跳
2.2: 实现
硬件:F5
软件:lvs nginx
2.3:映射
A、B登陆,保存 (lbs)<uid, Front channel>,(lbs)<uid, Back channel>,(redis)<uid, back server ip>,
A发送消息B,lbs从uid取得后端Back channel,发送到服务器1,服务器1先取得B的serverid:3 和ip,转发,server3接收,发还给lbs,lbs再发到B客户端Front channel
2.5 另一个负载均衡模型
2中的模型我觉得有点问题,负载均衡仍然会有大量连接,压力较大,未起到负载分散连接的作用,以下模型可以,而且更简洁:
client 与后端之间同样要建立心跳,之所以由proxy发起到后端的tcp连接而不是反过来,是因为保持后端的独立性
参考:https://blog.csdn.net/admin1973/article/details/71424160?utm_source=itdadao&utm_medium=referral
实践位于:https://www.cnblogs.com/silyvin/articles/9803778.html
https://mp.weixin.qq.com/s?__biz=MzUzMTA2NTU2Ng==&mid=2247484897&idx=1&sn=d1ebc9b4a46b15fb36732c7dba52d0a4&chksm=fa497a50cd3ef3460ba31e4c9e417dbd65d55fb3f9f9dfdbdd6943f9517fa096a8cd7af5e8c0&mpshare=1&scene=1&srcid=0812X16OOa3VbM3l3zove0pR&key=c76d92981ae751ea44818f34e9cba4717a846e53faa721f1a7bfd90a8ffacf5b30da581f9c51f9f29cefb4dadb70e1b34a78d0a005688923d0662ceefedbd98c87a145d21b2d6c94149a30c790069973&ascene=0&uin=MTA2NzUxMDAyNQ%3D%3D&devicetype=iMac+MacBookAir6%2C2+OSX+OSX+10.10.5+build(14F2511)&version=11020012&lang=zh_CN&pass_ticket=%2FbM7bjJct0cezZRCQGhjHoLNI%2F6kzz3pGwSOHQb0%2Bdd7hBMSHdRUm0qA%2BNc5bGeA
3 实践
3.1 重启
3.2 瞬间gc
轮询round robin,然后等待死链接平衡服务器
https://mp.weixin.qq.com/s?__biz=MzIwMzY1OTU1NQ==&mid=2247484608&idx=1&sn=dbdaa7a20f09a15e252cbef02bba20c1&chksm=96cd448ca1bacd9a127fc517d167e4210c8bc575417a50b23a782fc57ed210f92342fd4903cc&mpshare=1&scene=1&srcid=0927UEIblgcHUwUKBRJPenLI&key=ef42a6c1e4fdfbc6eb68e2ff391e4093d4cbb9e8ed1bac5f901262e1de5eef5198e8ebafc382cee35db594748d59a8fdd79312297f7483bc6aba154f7c6a7afc66ba23c9e2fb6415bd880b64abc0ae85&ascene=0&uin=MTA2NzUxMDAyNQ%3D%3D&devicetype=iMac+MacBookAir6%2C2+OSX+OSX+10.10.5+build(14F2511)&version=11020012&lang=zh_CN&pass_ticket=3sXqr7c2oEvhreALgBwX%2FGLK0mOv%2BqBK9kOHRAlS3NHnD19yGGWL0GX1fFKdJ7eU