I am trying to measure the latency when data are sent to the client from the server. My approach is calculating the difference between the server side and client side timestamp. Would this be a valid approach?
server.js
const timestamp = new Date().getTime()
io.emit('get_data', data, timestamp)
client.js
const [latency, setLatency] = useState(0)
(...)
useEffect(() => {
socket.on('get_data', (res, sentTime) => {
const currentTime = new Date().getTime()
const latency = currentTime - sentTime
},[socket])
I think this is not a good approach to measuring performance. This is a manual approach and you will not get the best estimation. Generally, we calculate performance based on statistics. The more sample you add to your test, you will get the better the estimation. I think load-testing is a good technique to stress the server. JMeter is probably the best option to perform load-testing.