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
Published at
2023-06-07 15:02:34Event JSON
{
"id": "9cb74abf9e327eb93c7eadb8f5443c65bb8266feddced2619fc2ac510e7da525",
"pubkey": "99bec497728c848e65549d1a5257d08de97621edcb4b77073269a45dac708d59",
"created_at": 1686150154,
"kind": 1,
"tags": [
[
"e",
"ef3511574a96b47529fa1d6c1878eeed24d9a6448c393b6a3a9eb7b72164923e",
"",
"root"
],
[
"e",
"de6b87789d462f62f2c1b2f02b02fae07248da7a33af6d22049782875c42a16d",
"",
"reply"
],
[
"p",
"b25e10e25d470d9b215521b50da0dfe7a209bec7fedeb53860c3e180ffdc8c11"
]
],
"content": "๐
Original date posted:2013-05-31\n๐ Original message:On Friday 31 May 2013 12:56:43 Rune Kjรฆr Svendsen wrote:\n\n\u003e I have an application that wants to keep up with new blocks as they come\n\u003e in. For that I can use the -blocknotify option with bitcoind, which will\n\u003e execute my application for each new block.\n\u003e \n\u003e The problem is that my app isn't necessarily quick enough to finish its\n\u003e work before a new block comes in and the app is executed again. This means\n\u003e the that bitcoind might keep executing my application even though the\n\u003e previous instance hasn't finished, and that's fairly inefficient\n\u003e resource-wise, as many instances of the application will be running\n\u003e simultaneously.\n\nHave your program try to create a unix-domain socket when it starts. If it \ncan't create it (because one already exists at that path), then connect to it.\n\nYou then have two modes:\n\n - Creator of socket, listens to socket for more incoming data, and adds it to\n some sort of internal block queue.\n - Client to socket, pushes output of -blocknotify to socket and exits\n\nYour concurrency problems go away because only one process is ever actually \ndoing something with the data.\n\nShould be fairly straight forward. The client is simple. The server is two \nthreads, one listening on the socket and then briefly locking and updating a \nqueue, and one thread briefly locking and removing from the queue.\n\n\n\nAndy\n\n-- \nDr Andy Parkins\nandyparkins at gmail.com",
"sig": "fa59866de6583ede8e7dea05e5fb4987d0d82bfaf4be17fc94017bd7b322885f751c0153b0a04cc780dad8d52a084c6e84bc7c0686dc8787f552770619b71acd"
}