public inbox for bitcoindev@googlegroups.com
 help / color / mirror / Atom feed
From: Andy Parkins <andyparkins@gmail.com>
To: bitcoin-development@lists.sourceforge.net
Subject: Re: [Bitcoin-development] Implementing batch processing for -blocknotify
Date: Fri, 31 May 2013 13:54:03 +0100	[thread overview]
Message-ID: <201305311354.03625.andyparkins@gmail.com> (raw)
In-Reply-To: <CAH2=CKzW41TYbX6c1F8oknA_LttOaA8vmDPmojuowXgEADY61g@mail.gmail.com>

On Friday 31 May 2013 12:56:43 Rune Kjær Svendsen wrote:

> I have an application that wants to keep up with new blocks as they come
> in. For that I can use the -blocknotify option with bitcoind, which will
> execute my application for each new block.
> 
> The problem is that my app isn't necessarily quick enough to finish its
> work before a new block comes in and the app is executed again. This means
> the that bitcoind might keep executing my application even though the
> previous instance hasn't finished, and that's fairly inefficient
> resource-wise, as many instances of the application will be running
> simultaneously.

Have your program try to create a unix-domain socket when it starts.  If it 
can't create it (because one already exists at that path), then connect to it.

You then have two modes:

 - Creator of socket, listens to socket for more incoming data, and adds it to
   some sort of internal block queue.
 - Client to socket, pushes output of -blocknotify to socket and exits

Your concurrency problems go away because only one process is ever actually 
doing something with the data.

Should be fairly straight forward.  The client is simple.  The server is two 
threads, one listening on the socket and then briefly locking and updating a 
queue, and one thread briefly locking and removing from the queue.



Andy

-- 
Dr Andy Parkins
andyparkins@gmail.com



  parent reply	other threads:[~2013-05-31 12:54 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-31 11:56 [Bitcoin-development] Implementing batch processing for -blocknotify Rune Kjær Svendsen
2013-05-31 12:10 ` Michael Hendricks
2013-05-31 12:37   ` Rune Kjær Svendsen
2013-05-31 19:25     ` Jeff Garzik
2013-05-31 12:54 ` Andy Parkins [this message]
2013-05-31 13:05 ` Jeff Garzik
2013-05-31 22:20 ` Chris Double
2013-05-31 23:29   ` Wladimir
2013-05-31 23:47     ` Chris Double
2013-06-01 13:12       ` Rune Kjær Svendsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201305311354.03625.andyparkins@gmail.com \
    --to=andyparkins@gmail.com \
    --cc=bitcoin-development@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox