java - Http Server speeds -


I have an application where I am making several requests to a server, through HTTP requests, to confirm the feedback I'm trying to bench. I do not know what to expect in terms of speed. I have written this sample program for testing. What should I expect from this program? About 4000 requests per second is getting which I think is less, please help.

HTTPClient:

package my.service; Import java.io.biteArrayOutputStream; Import java.io.InputStream; Import java.net.HttpURLConnection; Import java.net.URL; Import java.util.Date; Public class test client {public static zero major (string [] args throws exceptions {date date = new date (); For (Int i = 0; I <100000; i ++) {URL URL = New URL ("http://192.168.5.116:9999/ TestSpeed"); HttpURLConnection conn = (HttpURLConnection) url.openConnection (); Conn.setRequestMethod ("Post"); Conn.setRequestProperty ("content-type", "app / x-www-form-urxed"); Conn.setUseCaches (wrong); Conn.setDoInput (true); Conn.setDoOutput (true); Conn.connect (); InputStream stream = conn.getInputStream (); Bytereon OutputStream Boss = New Bytereunootstream (); Byte [] B = new byte [1]; While (stream.read (b)! = -1) {bos.write (b); } Byte [] Biteire = Bose. Batteryre (); String feedback = new string (byte); If (integer paraset% (= 1000 == 0) {System.out.println ("response to server -> + response); }} Date d1 = new date (); System.out.println (d1.getTime () - date.getTime ()); }

}

HTTPServer:

  package my.service; Import java.io.IOException; Import java.io.OutputStream; Import java.net.InetSocketAddress; Import java.util.concurrent.ExecutorService; Import java.util.concurrent.Executors; Import com.sun.net.httpserver.HttpExchange; Import com.sun.net.httpserver.HttpHandler; Import com.sun.net.httpserver.HttpServer; Public class test server (public static zero main) (string [] args exerts exception) {http server server = htepsor.credit (new inset socket adapter (99 99), 0); Executor Service Executor = Exporter. NewfixedThreadPool (10); Server.setExecutor (Executor Service); Server.createContext ("/ testSpeed", getHandler ()); Server.start (); } Private Static HttpHandler getHandler () {Return New TestHandler (); } Private Static Class Test Handler http Handler Operating {int i = 0; @ Override throws IOException Public Wide Handle (HTTPXback Request) {i ++; If (i% 1000 == 0) {System.out.println ("Receive the number of requests ->" + i); } String feedback = I + ""; Request.sendResponseHeaders (200, response.getBytes (.) Length); OutputStream OS = request.getResponseBody (); Write dew (feedback.); Os.close (); First of all, almost all application servers use fixed size thread pools. This approach is good but as you know that this reaction is very simple, in some situations you need to go to the database and wait for the response. In that situation you can not simulate accurate response times. 

Apart from this, your first concern is not the speed of reaction. You can configure the thread pool size for the application server. (Configurable). Besides, if the traffic is too heavy to handle then you need to open two or more servers. (Maybe load balancer can be used.).

In my opinion, you need to consider this situation because the product is alive but you need to implement the code for more than one server.


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -