Website and database on the same machine, localhost or ip?

Asked

Viewed 84 times

0

I have a website and database running on the same machine. And I use the following connection string:

<add name="cs_name" connectionString="server=227.117.126.60;User Id=DBUser;database=my_main_db; password=t3st#;Convert Zero Datetime=True;SslMode=none" />

I’m pointing to the server IP, but I could color localhost:3306

There is a difference between the two approaches when saying SPEED?

EDIT: personal excuse I wanted to exemplify an IP but ended up getting understood as local IP, the example is just a random IP, I will edit it to get better understanding.

The example is the connection of the application on the same machine as the database only one application calls the localhost and the other the public IP address of the machine itself.

  • 192.168.0.1 and localhost, if indeed they are the same machine, there is no "speed" difference, it is just a translation of the machine address. It’s not gonna change anything at all.

  • Caro @Filipel.Constant do not agree that it is a translation, I believe who solves the address, even if localhost or 127.0.0.1 is the operating system, independent of graphical interface or network adapters. By logic you could even make notes directly via /etc/hosts (linux) or c:\windows\system32\etc\hosts and any address would point to another. Of course the system identifies the interfaces, but it "chooses" what is returned (depending on how it was configured), so I don’t think we can call this "translation"

  • Good, then in this case only resorting to literature or an expert in the area p/ give us a precise north. : ) It is that business, living and learning.

  • @Filipel.Constant yes, I think Bacco understands this, maybe Anderson too, I hope Leonardo expects more answers, I’m just not sure if this is ON-TOPIC, because at first glance it seemed OFF, but I preferred not to vote for the closure, let’s wait for the community ;)

  • Guys, I edited the question I gave an example that ended up being misunderstood incorrectly.

1 answer

2


In theory, there is a difference. This is because 192.168.0.1, your local address, goes to the router to go to the server (which ironically, is the same client address).

However, your operating system is smart enough to know that it doesn’t need an intermediary to talk to itself.

To take the test, just compare the result of traceroute for 192.168.x.x and 127.0.0.1 (also known as localhost).

  • This does not make sense as it is the address of the machine, it has no sense to go out p/ then go back to itself.

  • In the case of localhost and 127.0.0.1, yes. But 192.168.0.1 and 127.0.0.1, not always.

  • I may be talking nonsense, but it is possible that the local machine solves the downloaded DHCP address in the "associated" network interface which maybe "cut the path""to go back and forth, but I’m kicking, really networking and ICMP I don’t understand. I think it would be nice to give a search on the subject to state better (assuming this is something solved in the operating system)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.