GithubHelp home page GithubHelp logo

Comments (10)

gagliardetto avatar gagliardetto commented on July 17, 2024

gm @whymidnight

an RPC client (client := rpc.New(endpoint)) is meant to be only one and used many times, potentially by many different callers at the same time.

from solana-go.

gagliardetto avatar gagliardetto commented on July 17, 2024

what's your use-case that requires throw-away clients?

from solana-go.

whymidnight avatar whymidnight commented on July 17, 2024

at one point in the past, i had baked in anchor events and spawned goroutines that contained some logic with many rpc calls upon receiving the message over the rpc websocket. i wasnt sure if this was threadsafe at the time so it seemed more elegant to instead instance a new rpc struct inside the callback so that each goroutine had its own rpc client. however this didnt scale because of the above issue.

additionally, this approach of passing an rpc.Client pointer to functions that require does not allow for go modules to contain their own rpc lifecycle like - for instance: i have a utilities module for sending transactions, parsing chain state, etc; another module for my chain program; and some arbitrary third module.

if i wanted to import these modules in a disparate codebase, would require to also declare rpc.New in the main module which could be alleviated if the above modules could instance rpc.New themselves. however these modules must close their sockets to prevent the main module from exceeding open sockets.

from solana-go.

gagliardetto avatar gagliardetto commented on July 17, 2024

and you're doing the same thing with websocket clients?

from solana-go.

whymidnight avatar whymidnight commented on July 17, 2024

well i can foresee this applying to websocket clients as well like awaiting for signature confirmations via ws in a confined thread inside the main thread.

from solana-go.

gagliardetto avatar gagliardetto commented on July 17, 2024

the websocket client is also thread-safe and supports multiple concurrent subscriptions.

from solana-go.

whymidnight avatar whymidnight commented on July 17, 2024

however the http client design means that disparate modules are dependent on the main thread passing a pointer which isn't as elegant when modules could manage their own lifecycle of it. however is actually probably bad design in the bigger scheme of things since this means >1 rpc.Client versus 1 global rpc.Client. as the issue of exceeding open sockets could still arise.

from solana-go.

gagliardetto avatar gagliardetto commented on July 17, 2024

the rpc client is made to be as efficient as possible (reusing TCP connections, enabling gzip compression, etc.)

if you don't want all of that, you'll waste time & resources reconnecting for each RPC call (maybe even having to make a DNS resolution).

from solana-go.

gagliardetto avatar gagliardetto commented on July 17, 2024

for instance: i have a utilities module for sending transactions, parsing chain state, etc; another module for my chain program; and some arbitrary third module.

great! use 3 rpc clients 😁

from solana-go.

whymidnight avatar whymidnight commented on July 17, 2024

if you don't want all of that, you'll waste time & resources reconnecting for each RPC call (maybe even having to make a DNS resolution).

thats exactly what i needed to hear. it took a discussion to realise this lol. thank you! i'll close this issue now.

much love,
D.

from solana-go.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.