On Oct 21, 2020, at 6:41 AM, Bill <billyp...@gmail.com> wrote:
> 
> Hello, 
> I created the sql to fetch all info in one call instead of multiple calls per 
> each row.
> 
> One thing I noticed about golang is that when I ping my Remote DB from 
> localhost (running in vscode) I get ping -> 1.573826274s. So I think this is 
> the reason that all my calls to db are delayed.
> Have you any idea what can be the issue? Maybe a clean install of Golang in 
> MacOSX could fix this issue? If I test the code in server (upload the binary) 
> the response time is normal (200ms - 300ms).
> 
> My Code to ping: 
> 
> begin := time.Now()
> err := Config.DB.Ping()
> log.Printf("Ping in %s (%v)", time.Since(begin), err)

So Ping() just gets a response from the server, but it's not really defined how 
simple an operation that is.  If you have a high latency connection (e.g. 
international distances, slow/lossy connection, etc) to your database, it might 
only take a few round trips to reach over a second.  Honestly, 200 ms sounds 
excessively long for an on-server response if it's just going to localhost, 
though I suppose it depends on how loaded the database is.

In any case, if a simple database ping is taking a second and a half, it's 
reasonable to assume that a number of transactions which depend on each other 
could easily amount to 10s.  This is where joins are handy, because the 
database is actually generally really good at shuffling all that data around on 
its own before sending it back to you in one lump.  A good join (especially if 
you've done your indexing right) will improve both your latency and your code 
complexity immensely.  It sounds like you may have already done that, in which 
case I assume you've seen some improvement.

As to why it takes so long in the first place: where are you located relative 
to where the database server is located?  What's the response time from a 
regular command-line database ping?  If you're, say, on the other side of the 
world, it's going to take a while for each round trip, and there's not much way 
around that other than trying to keep things somewhat closer together where 
possible (and also reduce or parallelize the round trips where possible).  
There are fundamental limitations in re: the speed of light when it comes to 
latency, no matter what your bandwidth.


- Dave


-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/BD2B7CCD-73B9-4540-B7E5-7F413F16BC47%40gmail.com.

Reply via email to