Why Nostr? What is Njump?
2023-06-07 15:02:34

Andy Parkins [ARCHIVE] on Nostr: ๐Ÿ“… Original date posted:2013-05-31 ๐Ÿ“ Original message:On Friday 31 May 2013 ...

๐Ÿ“… Original date posted:2013-05-31
๐Ÿ“ Original message: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 at gmail.com
Author Public Key
npub1nxlvf9mj3jzgue25n5d9y47s3h5hvg0ded9hwpejdxj9mtrs34vs97wjrv