POST response is too long

Ajax Javascript client code uses XMLHttpRequest to send a POST request, but I get a 0.5 second delay in receiving the response, and I'm trying to figure out why, because I would like it to be faster, more than 0.2 seconds. Both endpoints are on the same intranet, the client is directly connected via ethernet and the server using 802.11b.

Using Wireshark, I looked at the following TCP transactions:

  Time (ms) From To Info
 -------------------------------------------------- ----------------------
 0.0 client server [SYN]
 11.7 server client [SYN, ACK]
 11.8 client server [ACK]
 12.0 client server [POST]
 12.1 client server Continuation
 39.0 server client ACK
 46.0 server client ACK
 150.0 server client TCP segment of reassembled PDU
 311.0 client server ACK
 324.0 server client HTTP / 1.1 200 OK (text / html)
 512.0 client server ACK

The actual message and response are really short. Basically the content of the POST request:

 cmd=getCurXY&chan=CH_L_JX 

And the content of the response I'm sending right now is simple:

 cmd=noresponse 

The response is sent as Transfer-Encoding: chunked .

Can this transaction speed up somehow?
Why do I need a whole half second?

+4
source share
1 answer

At first, I highly recommend that you add this gem to your development team stones in your gemfile.

 group :development, :test do gem 'rack-mini-profiler' end 

It allows you to track transaction time when you execute AJAX requests or any request from a web browser. Also remember that Webrick (the default development server used by Rails) is a rather slow development server, so if you can recommend you use Puma as a development server and Unicorn as Production.

Also, do you really need to use a Rails controller to manage these requests? A very good implementation for such projects is the use of middleware. It’s still ruby ​​code, but it doesn’t load all the functions of Rails, which makes answers faster. You can find more information at http://railscasts.com/episodes/319-rails-middleware-walkthrough

Sincerely.

0
source

Source: https://habr.com/ru/post/1286724/


All Articles