同一个ip下用3千个线程去请求,而真实场景是3千个不同的ip,前一种情况可以复用socket,似乎真实场景要更慢,有办法模拟吗?
并发测试代码
import requestsimport timeimport threading s=time.time() def get(): r=requests.get('http://localhost:3000?id='+str(i)) #print(threading.currentThread()) #print(r.text)for i in range(1,3000): threading.Thread(target=get).start()print(time.time()-s)
服务端代码,,写入3000条数据,用时11秒左右,1000条则是3秒左右,有办法优化吗?
var http = require('http');var url =require('url')var mysql = require('mysql');var connection = mysql.createConnection({ host : 'localhost', user : 'root', password : 'root', database : 'test'}); connection.connect(); http.createServer(function(req, res){ //res.writeHead(200, {'Content-Type': 'text/plain'}); id=url.parse(req.url, true).query.id; connection.query('INSERT INTO speed(num) values ('+id+')') //connection.query('select id from speed where num='+id)}).listen(3000)
眼眸繁星
相关分类