Skip Menu |

This queue is for tickets about the Audio-MPD CPAN distribution.

Report information
The Basics
Id: 31050
Status: resolved
Priority: 0/
Queue: Audio-MPD

People
Owner: jquelin [...] cpan.org
Requestors: joey [...] kitenet.net
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.18.2
Fixed in: (no value)



Subject: man page is misleading about connection caching
Since the man page says "A connection to the MPD server is established as soon as a new Audio::MPD object is created.Commands are then sent to the server as the class’s methods are called." -- I got the impression that one connection is used for the whole session for the object. I was saddened to find that this isn't true, and that my programs are, as a consequence, rather slow. Is this planned to be fixed? Should I use the POE module instead?
Le Mer. Nov. 28 23:28:34 2007, JOEY a écrit : Show quoted text
> Since the man page says "A connection to the MPD server is established > as soon as a new Audio::MPD object is created.Commands are then sent > to the server as the class’s methods are called."
humm no, the module opens a new connection for each command issued. Show quoted text
> I got the impression that one connection is used for the whole > session for the object. I was saddened to find that this isn't true, > and that my programs are, as a consequence, rather slow.
my mistake, it's some remaining stuff from the original module that i inherited when i took over ownership. the original code was doing that, but: - it was buggy as hell, checking for timeouts but resulting in endless loops - network connections were not correctly monitored / reset / checked / etc. i therefore dumped this scheme for the safer (but slower) scheme: one connection per command i *know* it sucks, but network programming is a pita to do correctly. in the same time, i decided to try to write a poe module that would be better networking-wise, since poe would manage all the non-blocking socket i/o for me... (for the records, check http://groups.google.fr/group/audio-mpd/browse_frm/thread/2a738cd980793cb0#de40453995def4ed for the discussion of this change. there are some references to parts of the old code, but...) Show quoted text
> Is this planned to be fixed?
i'm going to fix the documentation. not sure that releasing a 0.18.4 version is worth it - what do you think? regarding fixing the code: i'm not sure i want to go down that road. would you be interested to supply some patches to fix it? :-) (note that i cleaned up the code to always call the _send_command() method, therefore changing the connection scheme "only" means changing this method) Show quoted text
> Should I use the POE module instead?
the poe module is indeed better for this: it keeps a connection open to the mpd server, and it reconnects automatically if somehow deconnected. having said that, please note that the poe module design is not finished. i'm not satisfied by its current api / internals, and i guess it might change in future releases. (it's mostly my fault, since it was the first poe programming that i've did) however, if you are: - concerned by network latencies implied by audio::mpd (are you accessing a remote server? then how do you listen to the music? via some icecast?) - ready to adapt to future api changes, - ready to change your program to be poe-aware (it's a nice framework btw) ==> the poe module is definitely the module you want to look at.
Subject: Re: [rt.cpan.org #31050] man page is misleading about connection caching
Date: Thu, 29 Nov 2007 11:54:10 -0500
To: Jerome Quelin via RT <bug-Audio-MPD [...] rt.cpan.org>
From: Joey Hess <joey [...] kitenet.net>
Download signature.asc
application/pgp-signature 189b

Message body not shown because it is not plain text.

Jerome Quelin wrote: Show quoted text
> my mistake, it's some remaining stuff from the original module that i > inherited when i took over ownership. > > the original code was doing that, but: > - it was buggy as hell, checking for timeouts but resulting in endless > loops > - network connections were not correctly monitored / reset / checked / etc. > > i therefore dumped this scheme for the safer (but slower) scheme: > one connection per command > > i *know* it sucks, but network programming is a pita to do correctly. > > in the same time, i decided to try to write a poe module that would be > better networking-wise, since poe would manage all the non-blocking > socket i/o for me... > > (for the records, check > http://groups.google.fr/group/audio-mpd/browse_frm/thread/2a738cd980793cb0#de40453995def4ed > for the discussion of this change. there are some references to parts of > the old code, but...)
Something not mentioned in that thread is that every potential hang mentioned there still exists in Audio::MPD. If the server crashes in between it sending the password line and it sending the command, the client will still hang, for example. Show quoted text
> > Is this planned to be fixed?
> > i'm going to fix the documentation. not sure that releasing a 0.18.4 > version is worth it - what do you think?
Well, I might have skipped over trying the module if its docs had said it needed one connection per command. Show quoted text
> regarding fixing the code: i'm not sure i want to go down that road. > would you be interested to supply some patches to fix it? :-) > (note that i cleaned up the code to always call the _send_command() > method, therefore changing the connection scheme "only" means changing > this method)
Well, it seems to me that you could add a flag that enables an unsafe mode where one connection is reused, and if the server times out/goes away/connection is dropped, the client is on its own to notice this and avoid hanging. Or on its own to let it hang. For certian types of clients, it doesn't really matter if they don't deal gracefully with issues with the connection. For some others, it's easy enough to set up an alarm and abort or retry. IO::Socket::INET also has some options that can be used for simple handling of timeouts, for some programs it might be enough for them to get at and tune those options for their use cases. Show quoted text
> > Should I use the POE module instead?
> > the poe module is indeed better for this: it keeps a connection open to > the mpd server, and it reconnects automatically if somehow deconnected. > > having said that, please note that the poe module design is not > finished. i'm not satisfied by its current api / internals, and i guess > it might change in future releases. (it's mostly my fault, since it was > the first poe programming that i've did)
I looked at it, but it seemed much more difficult to program for if I want to do a simple client that runs some scripted set of commands. Maybe there's an easy way to do that that I didn't see, I am not really familiar with POE. Show quoted text
> however, if you are: > - concerned by network latencies implied by audio::mpd (are you > accessing a remote server? then how do you listen to the music? via some > icecast?)
The particular cases where multiple connections annoyed me were a) Writing a program to copy the state of one mpd to another, I wanted to seek them to the same play position as closely as possible, and this works less well than I'd have hoped since it has to open a new connection to each, rather than using an existing open connection, which would be much faster. b) Writing a program to reverse the playlist, which involved a lot of move operations, and this is where I really noticed it was reconnecting per command, since the program is unusable with any sizable playlist. FWIW, my current set of code using Audio::MPD is at git://git.kitenet.net/mpdtoys -- see shy jo
Download (untitled)
application/x- 2.5k

Message body not shown because it is not plain text.

Le Jeu. Nov. 29 11:54:50 2007, JOEY a écrit : Show quoted text
> Jerome Quelin wrote:
> > (for the records, check > > http://groups.google.fr/group/audio-
> mpd/browse_frm/thread/2a738cd980793cb0#de40453995def4ed
> > for the discussion of this change. there are some references to
> parts of
> > the old code, but...)
> > Something not mentioned in that thread is that every potential hang > mentioned there still exists in Audio::MPD. If the server crashes in > between it sending the password line and it sending the command, the > client will still hang, for example.
yup it is: "and it does not even protect us from problems appearing between write & read." Show quoted text
> > > Is this planned to be fixed?
> > > > i'm going to fix the documentation. not sure that releasing a 0.18.4 > > version is worth it - what do you think?
> > Well, I might have skipped over trying the module if its docs had said > it needed one connection per command.
and you would have missed my great piece of software! :-) Show quoted text
> > regarding fixing the code: i'm not sure i want to go down that road. > > would you be interested to supply some patches to fix it? :-) > > (note that i cleaned up the code to always call the _send_command() > > method, therefore changing the connection scheme "only" means
> changing
> > this method)
> > Well, it seems to me that you could add a flag that enables > an unsafe mode where one connection is reused, and if the server > times out/goes away/connection is dropped, the client is on its > own to notice this and avoid hanging. Or on its own to let it hang.
that's an interesting proposition. i'll implement it. Show quoted text
> b) Writing a program to reverse the playlist, which involved a lot of > move operations, and this is where I really noticed it was > reconnecting per command, since the program is unusable with any > sizable playlist.
uh, this one is easy: get playlist with as_items, reverse it, clear the playlist, and add the reversed playlist. Show quoted text
> FWIW, my current set of code using Audio::MPD is at > git://git.kitenet.net/mpdtoys
i really need to learn a bit git.
Subject: Re: [rt.cpan.org #31050] man page is misleading about connection caching
Date: Thu, 29 Nov 2007 13:26:56 -0500
To: Jerome Quelin via RT <bug-Audio-MPD [...] rt.cpan.org>
From: Joey Hess <joey [...] kitenet.net>
Jerome Quelin: Show quoted text
> > Well, it seems to me that you could add a flag that enables > > an unsafe mode where one connection is reused, and if the server > > times out/goes away/connection is dropped, the client is on its > > own to notice this and avoid hanging. Or on its own to let it hang.
> > that's an interesting proposition. i'll implement it.
Thanks! Show quoted text
> uh, this one is easy: get playlist with as_items, reverse it, clear the > playlist, and add the reversed playlist.
Well, clearing the playlist stops the current song playing, I reversed the playlist around the current song so it kept going.. -- see shy jo
Download signature.asc
application/pgp-signature 189b

Message body not shown because it is not plain text.

0.19.0 on its way to cpan, allowing to change connection way of working. note that constructor api has changed: my $mpd = Audio::MPD->new( host=>$h, port=>$p, password=>$pw, conntype=>$t ); where conntype can be either $REUSE or $ONCE (the default). marking bug corrected.