joaonrb
joaonrb

Reputation: 1021

How can I use Riak connection pool with Beego Framework

I'm developing a back-end using Beego and Riak. I'm searching for a way to keep the riak connection pool alive but I cannot find nothing in documentation besides SQL related.

I'm really freshman to the Go language (started learning 2 days ago) and I don't know if connection pool is the write choice. As I understand, each Go app should be designed to work independently allowing easy scalability. If this is write maybe a single connection should be better choice. If this is the case, what is the best practice I can use?

I'm sorry in advance if my question seems noobie, but, with my Django background, I'm not used to manage db connections.

The riak connector I'm using is "github.com/tpjg/goriakpbc"

Upvotes: 0

Views: 278

Answers (1)

Joe
Joe

Reputation: 28316

Whether or not to use a connection pool depends more on your usage pattern and workload that your choice of data store or client library.

Each time a TCP connection is established, there is a three-way handshake:

  1. client --syn--> server
  2. client <--syn-ack-- server
  3. client --ack--> server

This usually takes a very small amount of time and network bandwith, and creates an entry in the conntrack table on each machine. If your application opens a new connection to the server for every request and will be sending many thousands of requests per second, you may overflow the conntrack table, blocking new connections until some previous connections close; or the overhead traffic of creating connections could limit how many requests you can handle per second.

If you decide to use a pool and use short-lived processes that handle a single request and then terminate, you will need some method of creating and maintaining connections separately from the request processes, and a method for the request processes to send requests and receive responses using a connection from the pool.

You may find that if your application does not generate a sufficient volume of traffic, the effort required to design your application to use a connection pool outweighs any benefits gained by using a pool.

There is not right or wrong answer, this is going to heavily depend on your use case, request volume, and network capabilities.

Upvotes: 2

Related Questions