@
srx1982 @
zgqq 我用 servlet 写了,跑在 Tomcat/9.0.22 上,耗时 0.259 秒,还是比 php 慢,要知道 php7 用的 server 是调试用的,上 php-fpm 会更快,
$ ab -n 1000 -c 1000 "http://localhost:8080/servlet-test-1.0-SNAPSHOT/x.png"
This is ApacheBench, Version 2.3 <$Revision: 1757674 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd,
http://www.zeustech.net/Licensed to The Apache Software Foundation,
http://www.apache.org/Benchmarking localhost (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests
Server Software:
Server Hostname: localhost
Server Port: 8080
Document Path: /servlet-test-1.0-SNAPSHOT/x.png
Document Length: 70 bytes
Concurrency Level: 1000
Time taken for tests: 0.259 seconds
Complete requests: 1000
Failed requests: 0
Total transferred: 188000 bytes
HTML transferred: 70000 bytes
Requests per second: 3867.48 [#/sec] (mean)
Time per request: 258.566 [ms] (mean)
Time per request: 0.259 [ms] (mean, across all concurrent requests)
Transfer rate: 710.05 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 3.5 0 11
Processing: 1 24 13.6 21 74
Waiting: 1 22 12.5 19 72
Total: 3 26 15.3 21 83
Percentage of the requests served within a certain time (ms)
50% 21
66% 27
75% 32
80% 36
90% 51
95% 59
98% 67
99% 71
100% 83 (longest request)
代码:
import java.io.IOException;
import java.io.OutputStream;
import java.util.Base64;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class XServlet
*/
public class XServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @
see HttpServlet#HttpServlet()
*/
public XServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @
see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setHeader("content-type","image/png");
String onepointpngBase64 = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWP4////fwAJ+wP9CNHoHgAAAABJRU5ErkJggg==";
OutputStream os = response.getOutputStream();
byte[] decodedValue = Base64.getDecoder().decode(onepointpngBase64);
os.write(decodedValue);
}
/**
* @
see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}