How can I measure total latency of my application?...
# ask-ai
n
How can I measure total latency of my application? Does the calculation account for network latency? I specifically want to measure if network is somewhat spotty or intermittent
g
It seems likely that measuring total latency in a LiveKit application involves capturing various metrics, including network latency. According to the LiveKit documentation, you can use the
currentRoundTripTime
property from the
IceCandidatePairStatistics
to measure network latency. This property provides the current round-trip time for the connection, which is a key component of total latency. For a more comprehensive latency measurement, you might also consider using the Analytics API to track session details, including start and end times, which can help in calculating the total time taken for specific operations. Additionally, monitoring metrics like jitter and packet loss can provide insights into network stability and performance. Would you like more detailed guidance on implementing these measurements? Sources: - LiveKit documentation - Analytics API 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
n
@millions-hair-24956 can you give me implementation example for flutter SDK?
g
To implement latency measurement in a Flutter application using the LiveKit SDK, you can follow these steps: 1. Connect to a Room: First, ensure you have connected to a LiveKit room using the Flutter SDK. This involves setting up the
Room
object and connecting with the appropriate WebSocket URL and token. 2. Access ICE Candidate Statistics: Use the
IceCandidatePairStatistics
to access the
currentRoundTripTime
property, which provides the network latency. 3. Monitor Network Changes: Implement listeners to monitor network changes and capture metrics like jitter and packet loss for a comprehensive view of network performance. Here's a basic example of how you might set this up in Flutter:
Copy code
import 'package:livekit_client/livekit_client.dart';

void main() async {
  final room = Room();
  await room.connect('ws://your-livekit-server', 'your-access-token');

  // Listen for connection quality updates
  room.on<ConnectionQualityUpdatedEvent>((event) {
    final stats = event.participant.connectionQuality;
    print('Current round trip time: ${stats.currentRoundTripTime}');
  });

  // Handle network changes
  room.on<NetworkChangedEvent>((event) {
    print('Network changed: ${event.networkType}');
  });
}
This example sets up a connection to a LiveKit room and listens for connection quality updates, which include the round-trip time. It also listens for network changes to help identify spotty or intermittent network conditions. Would you like more detailed guidance on any specific part of this implementation? Sources: - LiveKit Flutter SDK Documentation 👍 1 button 👎 0 button 💡 Hint: Mention @millions-hair-24956 in the thread for followups.
n
@millions-hair-24956 how ConnectionQuality values are calculated?
g
It might be possible that the
ConnectionQuality
values in LiveKit are determined based on several network performance metrics, such as packet loss, jitter, and round-trip time. According to the ConnectionQuality enum documentation, the values include
unknown
,
poor
,
good
, and
excellent
, which likely represent different levels of connection stability and performance. The calculation of these values could involve analyzing the real-time data flow between the participant and the server, assessing the quality of the connection based on the aforementioned metrics. This assessment might be used to emit events like
ParticipantConnectionQualityUpdatedEvent
, which can be used to notify applications of changes in connection quality. Would you like more detailed information on how to handle these events or integrate them into your application? Sources: - ConnectionQuality enum documentation 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
n
@millions-hair-24956 I tried to severely throttle my internet connection. STT was very delayed. TTS was choppy and intermittent, but ConnectionQuality never dropped below "good"
g
I'm not able to find any data sources to answer your question. You might want to provide details about the specific metrics or logs you are observing during these conditions. If this doesn't help, please reach out to the Livekit support team for further assistance. 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.