WhatsApp如何实现每个服务器200万个连接? [英] How did WhatsApp achieve 2 million connections per server?

查看:914
本文介绍了WhatsApp如何实现每个服务器200万个连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Ubuntu上,可以打开的最大套接字数似乎受以下条件的限制:

On Ubuntu, the maximum number of sockets which can be opened seems to be governed from following:

$ cat /proc/sys/net/ipv4/tcp_max_orphans
262144

根据Rick的一个演示文稿Reed(来自WhatsApp),这些人在使用FreeBSD和ErLang的单一服务器上接受了200万次并发连接。我的理解是,我们将永远需要内核的一些支持。是的,看起来像是调整了FreeBSD让这个能力

As per one of the presentations by Rick Reed (from WhatsApp), these guys took it up to 2 million concurrent connections on a "single server" using FreeBSD and ErLang. My understanding is that we will always need some support from the kernel. And yes, looks like the tweaked the FreeBSD to have this capability:

hw.machine: amd64
hw.model: Intel(R) Xeon(R) CPU X5675 @ 3.07GHz
hw.ncpu: 24
hw.physmem: 103062118400
hw.usermem: 100556451840

kb@c123$ uname -rps
FreeBSD 8.2-STABLE amd64

jkb@c123$ cat /boot/loader.conf.local
kern.ipc.maxsockets=2400000
kern.maxfiles=3000000
kern.maxfilesperproc=2700000

所以,看起来像内核可以调整来支持这么多的物理连接,因为我们有足够的内存量,正确吗?如果是的话,那么它看起来很简单,那么什么是炒作呢?或者我错过了一些东西?

So, looks like kernel can be tweaked to support so many physical connections, given that we have sufficient amount of memory, correct? If yes, then it looks pretty simple, then what is the hype about it? Or I am missing something?

谢谢。

推荐答案

这里有三件事:


  1. 让服务器支持200万个连接。这通常只是调整内核,使得允许同时连接的数量,并且使得与每个连接相关联的上下文适合(有线)主存储器。后者意味着您不能为每个连接分配一个兆字节缓冲区空间。

  1. Getting the server to support two million connections. This is usually just tweaking the kernel such that the number of simultaneous connections are allowed and such that the context associated with each connection fit in (wired) main memory. The latter means you can't have a megabyte buffer space allocated for each connection.

在每个连接中执行某些操作。在一个进程中将它们映射到用户空间(在这种情况下为Erlang)。现在,如果每个连接在用户空间级别分配太多的数据,我们将返回到正方形。我们无法做到这一点。

Doing something with each connection. You map them into userspace in a process (Erlang in this case). Now, if each connection allocates too much data at the user space level we are back to square one. We can't do it.

使用多个内核来实现连接。这是必要的,因为要完成的工作量很大。这也是你想避免锁定太多等等的一点。

Getting multiple cores to do something with the connections. This is necessary due to the sheer amount of work to be done. It is also the point where you want to avoid locking too much and so on.

你似乎专注于单独一个。

You seem to be focused on 1. alone.

这篇关于WhatsApp如何实现每个服务器200万个连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆