3 ms·
When I converted all the micro services in my big app from HTTP to WebSockets my test automation performance in the browser instantly became 7x faster. I am sti
by austin-cheney 4y ago
When I converted all the micro services in my big app from HTTP to WebSockets my test automation performance in the browser instantly became 7x faster. I am still using JSON and not using protobuf.
The reason for the performance difference is that a WebSocket is a single statefull TCP socket with a tiny extra binary frame header sending messages back and forth. HTTP is stateless so it creates a new socket for each and every message. HTTP also has a round trip, request/response. The round trip means twice the message frequency as compared to the fire and forget nature of WebSockets.
- magicalhippo 4y ago> HTTP is stateless so it creates a new socket for each and every message Well, HTTP 1.1 supports persistent connections and pipelining[1]. Though I suppose if you're a JavaScript in the browser it's easier to just use WebSockets. [1]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Connection_management_in_HTTP_1.x https://developer.mozilla.org/en-US/docs/Web/HTTP/Connection...
- hardwaresofton 4y agoOn the server side what do you use? Is it custom code to essentially reimplement the usual RPC patterns and multiplexing, etc? Or are you using something like trpc?[0] Another thing I’ve also thought is that Content-Type plus the appropriate headers could easily open up using compressed/efficient binary serialization on the web as well and unlock even further gains. One thing though is the issues with how websockets complicate scaling horizontally for simple request handling. [0]: https://trpc.io/docs/subscriptions https://trpc.io/docs/subscriptions
- austin-cheney 4y agoOn the server I use WebSockets between peers. I use my own WebSocket implementation but I try to stay within RFC6455 even when not talking to browser just so that I have a uniform format processing. I can see how protobuf would be handy if you are just talking only to a database or directly transmitting a binary BLOB, but I rarely do any of that. Most of my messaging are microservices used by the application so I just use JSON.stringify for each message. I know there is overhead to that, but it works well for me. I should probably find a way to pull my application data directly into a binary format and back out without string handling, but I have not figured this out yet. Instead of 7x faster than HTTP my message handling would be 10-11x faster than HTTP.