Bitcoin Forum

Bitcoin => Mining => Topic started by: shads on June 17, 2011, 06:50:24 AM



Title: Can some explain long polling?
Post by: shads on June 17, 2011, 06:50:24 AM
I've searched a lot but not really found an explanation of what it is or how it works.

I'm keen to get to work on a java implementation of a pool server.  It sounds to me like it's some sort of persistent HTTP connection that allows the server to push a message back to the client sometime after the getwork response has been sent to inform them that the block is finished and they need to get some fresh work to do. Is that the basic idea?

If so is there any doco or spec for it so I can make sure my pool server implements it correctly?


Title: Re: Can some explain long polling?
Post by: redhatzero on June 17, 2011, 07:00:43 AM
I think deepbit has a good documentation of LP somewhere on their site.
Basically it's a http connection, you open it and then it's blocking until a new block is found. When a new block is found it returns the same stuff as a getwork would have done.

That's the whole magic


Title: Re: Can some explain long polling?
Post by: botnet on June 17, 2011, 06:15:59 PM
http://en.wikipedia.org/wiki/Comet_(programming)

it's still a polling model for data, but the server holds the connection open until there is new data or it times out. 


Title: Re: Can some explain long polling?
Post by: pwnyboy on June 17, 2011, 06:26:48 PM
It's basically as the OP described - a persistent HTTP connection that is held open until the global blockchain increments.  At that point, the long polling server sends back a getwork response for the new block and closes the connection.  It's fairly easy to get sample data; just fire up Phoenix or poclbm in Linux and run tcpdump.


Title: Re: Can some explain long polling?
Post by: shads on June 18, 2011, 01:04:49 AM
thanks for link, that makes it a lot clearer so I can get to work now... The only part I'm not clear on is this:

Quote
4) If all the nonce space is exhausted during calculation or 60 seconds passed since receiving the data, the miner should request new one by means of main connection. 60 seconds limit is set to allow adding new transactions into the block.

Does this mean that the long poll itself should be dropped and reconnected every 60 seconds?  Or is it only talking about the main connection.

Also the long poll request is basically identical to a getwork request except for the different URL and lack of timeout?


Title: Re: Can some explain long polling?
Post by: 1bitc0inplz on June 18, 2011, 01:23:49 AM
thanks for link, that makes it a lot clearer so I can get to work now... The only part I'm not clear on is this:

Quote
4) If all the nonce space is exhausted during calculation or 60 seconds passed since receiving the data, the miner should request new one by means of main connection. 60 seconds limit is set to allow adding new transactions into the block.

Does this mean that the long poll itself should be dropped and reconnected every 60 seconds?  Or is it only talking about the main connection.

Also the long poll request is basically identical to a getwork request except for the different URL and lack of timeout?

When the pool terminates the LP connection, it does so to specify that new work is available. What the pool does is sends fresh "getwork" to the miner and drops the connection. The miner then knows that they should stop working on any previous work, and only proceed with the new work. It also re-esthablishes a fresh LP connection to repeat the cycle.

The 60 second thing varies by miner. Many GPU miners, even on cards incapable of iterating the nonce range in 60 seconds, do multiple getworks per minute. All getwork occurs over normal connections, except getwork "pushed" to the mine when it's previous work is invalidated by the network finding a block.