Closed pavlosharhan2 closed 3 weeks ago
In truth I think this is a better question for Android folk, it might vary by device, OEM or platform version. The conscrypt folk (@prbprbprb ) might have more idea also.
I just checked on an emulator and got 1048576 as the default, so reducing on a slow network probably makes sense. But I don't think OkHttp has enough visibility to set this correctly.
Closing in favour of other discussions https://www.reddit.com/r/androiddev/comments/1fknl99/cellular_network_affects_socket_read_buffer_size/ and https://stackoverflow.com/questions/79002931/android-cellular-network-affects-socket-read-buffer-size-of-wifi-connections
I am investigating an issue where Wi-Fi transfers between my android app and GoPro are inconsistent across different cellular network conditions. Initially, I noticed that GoPro Quik (Official GoPro app) was able to transfer data efficiently even on 2G networks which wasn’t the case for my app. After some digging into their source code, I realized that Quik overrides OkHttp’s read_buffer_size to 512kb instead of the value okhttp uses depending on different quality of Cellular connection. Once I made the same adjustment in my app, it started transferring data well on 2G, which improved performance in those cases. However, this solution wasn’t perfect. Sometimes, transfers slowed down even on 4G, and I noticed that GoPro Quik also experienced slow transfer speeds in those instances. Interestingly, the speeds improved significantly once the cellular connection was disabled, suggesting there might be some interaction between the cellular and Wi-Fi networks affecting performance. I’m looking for ways of logging buffer sizes to investigate further and exploring how Android or the underlying Linux kernel might be influencing these behaviors.
Any suggestions or theories or where exactly the quality of cellular network may contribute are appreciated.
Here is my code for creating Okhttp client with a custom socket factory that overrides read_buffer_size: