0

I do not how to ask the question, but I am confused by how to manage sessions when the server is at local host.

Accessing the database direct

Without a middleware (REST), sessions are created as soon as you connect to the database. Even 2 connections from same computer gets 2 separate sessions.

enter image description here

Accessing via REST and localhost (127.0.0.1)

Using a middleware, all connections goes through 127.0.0.1 and there will be only 1 single session.

enter image description here

Is there a way to add unique sessions connecting the database when using localhost?

Any clue to handle this is appreciated.

  • Does it not depends on the number of connections? DB connections are not stateless. Each connection generates a session for a given User. The same user might have different sessions depending on the number of connections created. What leads us to the driver. DB drivers use to manage connections through connection pools. It's likely your Go driver has just created only one connection. Have you tried consuming the REST service concurrently with several clients? – Laiv Dec 12 '18 at 11:09
  • @laiv Direct access via tcp trigger automatically a new session. Indirect access via REST becomes one user. I do need a help to let the Go driver create sessions in some ways. I have not tried concurrently (some seconds apart though) with several clients. – sibert Dec 12 '18 at 11:57
  • I do need a help to let the Go driver create sessions in some ways why? This is unlikely to happen since it's contrary to the common practice of sharing connections (session) for several requests. It's a matter of efficiency. – Laiv Dec 12 '18 at 12:01
  • So is this normal to only have 1 session via localhost? – sibert Dec 12 '18 at 12:05
  • 1
    Not exactly. It's common to have a limited number of concurrent connections (or sessions) per client. Your localhost could create one or more connections depending the concurrency over the REST service and the connection's pool size – Laiv Dec 12 '18 at 13:07
0

The built in connection pools in Golang does the trick. Done some quick test and it seems to work.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.