0

I try to create a PHP server that can handle 1 Million Concurrent Connections using socket or if there are any other methods, the main goal is to write it in PHP may be with some special modules like "libevent".

At the moment I tune my Debian 7 Sysctl.conf:

### IMPROVE SYSTEM MEMORY MANAGEMENT ###

# Increase size of file handles and inode cache
fs.file-max = 2097152

# Do less swapping
vm.swappiness = 10
vm.dirty_ratio = 60
vm.dirty_background_ratio = 2

### GENERAL NETWORK SECURITY OPTIONS ###

# Number of times SYNACKs for passive TCP connection.
net.ipv4.tcp_synack_retries = 2

# Allowed local port range
net.ipv4.ip_local_port_range = 2000 65535

# Protect Against TCP Time-Wait
net.ipv4.tcp_rfc1337 = 1

# Decrease the time default value for tcp_fin_timeout connection
net.ipv4.tcp_fin_timeout = 15

# Decrease the time default value for connections to keep alive
net.ipv4.tcp_keepalive_time = 300
net.ipv4.tcp_keepalive_probes = 5
net.ipv4.tcp_keepalive_intvl = 15

### TUNING NETWORK PERFORMANCE ###

# Default Socket Receive Buffer
net.core.rmem_default = 31457280

# Maximum Socket Receive Buffer
net.core.rmem_max = 12582912

# Default Socket Send Buffer
net.core.wmem_default = 31457280

# Maximum Socket Send Buffer
net.core.wmem_max = 12582912

# Increase number of incoming connections
net.core.somaxconn = 65536

# Increase number of incoming connections backlog
net.core.netdev_max_backlog = 65536

# Increase the maximum amount of option memory buffers
net.core.optmem_max = 25165824

# Increase the maximum total buffer-space allocatable
# This is measured in units of pages (4096 bytes)
net.ipv4.tcp_mem = 65536 131072 262144
net.ipv4.udp_mem = 65536 131072 262144

# Increase the read-buffer space allocatable
net.ipv4.tcp_rmem = 8192 87380 16777216
net.ipv4.udp_rmem_min = 16384

# Increase the write-buffer-space allocatable
net.ipv4.tcp_wmem = 8192 65536 16777216
net.ipv4.udp_wmem_min = 16384

# Increase the tcp-time-wait buckets pool size to prevent simple DOS attacks
net.ipv4.tcp_max_tw_buckets = 1440000
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
fs.file-max = 65535

source: https://rtcamp.com/tutorials/linux/sysctl-conf/

recompile PHP 5.5.9 with: --enable-debug --enable-maintainer-zts --enable-fd-setsize=65535

Debian Changes increased FDs:

https://cs.uwaterloo.ca/~brecht/servers/openfiles.html

May be some suggestions or info where can I read how to create high load PHP server.

Update 1:

Lets try at first step to listen 65535!

tshepang
  • 12,111
  • 21
  • 91
  • 136
kivlara
  • 63
  • 1
  • 1
  • 9
  • 1kk concurrent connections. If you put up a second application node and a single load balancer, you can reduce the load by 50%. Scalability and reliable service cannot be setup by a single PHP server. – Daniel W. Mar 11 '14 at 10:38
  • OK! But at the moment I can't connect more then 1024, with all changes I made! And I don't know why. May be some PHP internal restrictions or OS restrictions ? I try to test it using ab (Apache Benchmarks). – kivlara Mar 11 '14 at 10:41
  • 1
    This one might help: http://stackoverflow.com/a/3923785/1948292 – Daniel W. Mar 11 '14 at 10:47

0 Answers0