I am working in real time trading application using Node.js(v0.12.4) and Socket.io(1.3.2). In that, I am facing some time delay nearly (100ms) when the response emitting from Node.js to GUI(Socket.Io).
I don't have a clue why the time delay is there while emitting data from Node.js to GUI (Socket.IO).
This happening in Production Site. And we tried to debug this in production server location also because of network latency. But same result.
Please anyone help me on this?
I am working in real time trading application using Node.js(v0.12.4) and Socket.io(1.3.2). In that, I am facing some time delay nearly (100ms) when the response emitting from Node.js to GUI(Socket.Io).
I don't have a clue why the time delay is there while emitting data from Node.js to GUI (Socket.IO).
This happening in Production Site. And we tried to debug this in production server location also because of network latency. But same result.
Please anyone help me on this?
Share Improve this question edited Feb 8, 2016 at 19:19 Tim 1,8462 gold badges27 silver badges48 bronze badges asked Feb 2, 2016 at 10:44 MadTechMadTech 1,4983 gold badges14 silver badges32 bronze badges 6- Which browser do you use (assuming the client is a web browser). What is your server configuration? What have you tried already in order to debug? – Mehdi Commented Feb 2, 2016 at 12:46
- Have a look at socket.io debug – Mehdi Commented Feb 2, 2016 at 12:47
- We have tried Chrome and Firefox. Both Browser we are facing time delay. We added time stamp before emitting the data from Node and after receiving the data from GUI(socket.io). The time difference is more than 100 ms – MadTech Commented Feb 2, 2016 at 13:17
- 2 There's really not enough information here for anyone to be able to help. Node.js is a single-thread application, so the delay could literally happen due to an unrelated, monly used script taking ~100ms to run. – jperezov Commented Feb 8, 2016 at 16:43
- 1 Could you verify that your production site is connecting to your client via websocket? I have faced similar issue when websocket was unable to reach node trough miss-configured proxy and socket.io felt back to long polling. – Koder Commented Feb 14, 2016 at 21:06
2 Answers
Reset to default 5 +25One huge thing to note before doing the following. When calculating timing from back-end(server side) to front end (client side) you need to run this on the same puter that uses the same timing crystal.
quartz crystal-driven timing even on high quality motherboards deffer from one another.
If you find no delay when calculating time delay from back-end(server side) to front end (client side) on the same pc then the delay you originally found was caused by either the network connection or the deference in the motherboards timing crystals. Which would eliminate Node.js and Socket.io as the cause of the time delay.
Basically you need to find out where the delay is happening before you can solve the problem.
What you need to do is find out what is causing the largest performance hit in your project. In order to do this you will need to isolate the time each process takes. You also need to measure the time delay from the initial retrieval of the data to the release of the data. Then measure the time delay of each function, method and process. Try to isolate the problem. You need to ask what is taking the most time to do?
In order to find out where your performance hit is ing from you need to do the following.
- Find out how long it takes for your code to get the information it needs.
- Find out how long each information manipulation process takes before it sends out the data i.e function/methods...
- After the information is sent out find how long it takes to get the information to the client side and load.
- Add all of the times up and make sure it is equal to your performance delay in order to insure you have all the data you require to isolate the performance leak.
- Order every method, function, process… by its time delay most time consuming to least time consuming. When you find what processes are causing the largest delays you will then be able to fix the problem... Or at least explore tangible solutions...
Here are some tools you can use to measure the performance throughout your code.
First: Chrome has a really good tool that lets you see the performance of each piece of executed code.
- https://developers.google./web/tools/chrome-devtools/profile/evaluate-performance/timeline-tool?hl=en
- https://developer.chrome./devtools/docs/timeline
Second: performance-now node package. You can use it for dev performance testing.
Third: Stack overflow post on measuring time/performance in js.
Fourth: you can use things like console.time()
- https://nodejs/api/console.html
- https://developer.mozilla/en-US/docs/Web/API/Console/time
- https://developer.chrome./devtools/docs/console-api
I have found out that time delay where it is happening.
Once, I have emitted the data from Client Socket to Node, I will show the some alert message ("Data Processed"). The alert message taking time to render in GUI.
This alert message blocking the response data from the Node to Socket.
Thanks for your help Guys.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745442409a4627889.html
评论列表(0条)