0

Apologies if my wording is not fully correct - I am quite new to all of this.

Goal: I am trying to improve the speed at which I get data from my database

Setup: I am hosting the DB on server A. The DB is also accessible via a website like www . mydbweb . com (not my actual website ofc). This access on the server side happens via Nginx with routs to something like localhost:1234.

Question: If I log inside the server and make a request to the DB via the website (i.e. www.mydbweb.com) the data will be fetched via the network (right?), but if I make a request via localhost:1234 directly, would this mean that no data is passed through the network?

In general, was is a way to skip the data being fetched through the network? I feel that the network does introduce some kind of a latency or bottleneck for large data queries.

Newskooler
  • 157
  • 1
  • 1
  • 10

1 Answers1

1

It depends a bit on the OS and network configuration but there is generally no significant speed difference in communicating with an external IP-address of a server or the localhost / loopback IP-address, as usually the operating system and network stack is aware that the external IP-address is also “this machine” and packets don’t go out on the wire but remain in-memory.

But the additional abstraction layer of nginx in the path between your application and database will add latency compared to having those two communicate directly.

The fastest way to connect your application to your database (when they are both running on the same host) is via a Unix socket (for a database running on Linux or a similar Unix OS ) or a similar direct connection. Such a connection takes away the need to encapsulate the requests and responses in network packets.

Bob
  • 5,335
  • 5
  • 24
  • Thanks @HermanB. Can I connect via a Unix socker while still being offering the access to the DB via NginX? – Newskooler Dec 14 '20 at 23:20
  • 1
    Generally speaking database servers will support concurrent use of all their supported connection protocols and methods, so I expect no problems there – Bob Dec 15 '20 at 07:49