bigger socket receive buffer?

I'm new to pianobar. You have a great project and community here... kudos to you all!

I was having a problem with songs pausing for several seconds on random occasions, probably due to glitches with my network or Pandora's servers. I resolved the issue wit hthe patch below and tuning up rmem_max to 5Mb from the Linux default of 256Kb (i.e., echo $((5_1024_1024)) > /proc/sys/net/core/rmem_max). With these two changes, the whole song is loaded into the kernel buffer right at the start and then pianobar streams the song from memory. This solved my intermittent song pausing.

Note that the patch itself doesn't change the current behavior unless you tune up rmem_max. It's simply giving folks the option to use a bigger buffer if they need to deal with this issue, which appears to come up here from time to time. For example, #329, #316, etc.

I'm new to github and haven't yet learned where or how to commit changes, but here's what I'm using locally. The first change allows for taking advantage of tuning up the OS socket receive buffer. The second change decreases the CPU load during the download and increased the speed of the download and should help if you are running on a slower computer like the old repurposed x86 laptop I'm using... :-)

Let me know your thoughts.

diff -up a/pianobar/src/libwaitress/waitress.c b/pianobar/src/libwaitress/waitress.c
--- a/pianobar/src/libwaitress/waitress.c   2013-09-08 06:26:01.000000000 -0500
+++ b/pianobar/src/libwaitress/waitress.c   2014-03-08 16:39:54.684881581 -0600
@@ -808,7 +808,7 @@ static WaitressReturn_t WaitressConnect
            fcntl (sock, F_SETFL, O_NONBLOCK);

            /* increase socket receive buffer */
-           const int sockopt = 256*1024;
+           const int sockopt = 5*1024*1024;
            setsockopt (sock, SOL_SOCKET, SO_RCVBUF, &sockopt,
                    sizeof (sockopt));

diff -up a/pianobar/src/libwaitress/waitress.h b/pianobar/src/libwaitress/waitress.h
--- a/pianobar/src/libwaitress/waitress.h   2013-05-08 11:55:16.000000000 -0500
+++ b/pianobar/src/libwaitress/waitress.h   2014-03-09 09:32:20.950476576 -0500
@@ -29,7 +29,7 @@ THE SOFTWARE.
 #include <stdbool.h>
 #include <gnutls>

-#define WAITRESS_BUFFER_SIZE 10*1024
+#define WAITRESS_BUFFER_SIZE 100*1024

 typedef enum {


2020/11/28 18:27
  • 点赞
  • 收藏
  • 回答