Re: [go-nuts] Golang slow performance inside for loop MySQL Queries

2020-10-22 Thread Jesper Louis Andersen
On Tue, Oct 20, 2020 at 6:51 PM wrote: > var count int > var favorited string > > fetchBookmarks := Config.DB.QueryRow("SELECT COUNT(*) FROM > favorites where userID = ? and postID = ? and status = ?", userID, postID, > "added").Scan(&count) > > if fetchBookmarks !

Re: [go-nuts] Golang slow performance inside for loop MySQL Queries

2020-10-21 Thread David Riley
On Oct 21, 2020, at 6:41 AM, Bill 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 thi

Re: [go-nuts] Golang slow performance inside for loop MySQL Queries

2020-10-21 Thread David Riley
On Oct 20, 2020, at 1:18 PM, Marcin Romaszewicz wrote: > > Go's database layer is generally pretty quick, I use it a lot, but your code > immediately sets off my DB alarms, because you are doing queries within the > body of another query loop, which means you're opening up lots of > connection

Re: [go-nuts] Golang slow performance inside for loop MySQL Queries

2020-10-21 Thread Marcin Romaszewicz
Can you connect to that DB any faster from the same machine not using Go? -- Marcin On Wed, Oct 21, 2020 at 3:43 AM Bill 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

Re: [go-nuts] Golang slow performance inside for loop MySQL Queries

2020-10-21 Thread Tamás Gulácsi
To reuse connections, and pay the slowness only on the first connection, set Config.DB.SetMaxIdleConns(2) Or something like that. As *sql.DB is a pool, this can keep two connections alive - one for your main query, and one for the per-row extra queries. Bill a következőt írta (2020. októbe

Re: [go-nuts] Golang slow performance inside for loop MySQL Queries

2020-10-21 Thread Bill
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. Hav

Re: [go-nuts] Golang slow performance inside for loop MySQL Queries

2020-10-20 Thread Marcin Romaszewicz
Go's database layer is generally pretty quick, I use it a lot, but your code immediately sets off my DB alarms, because you are doing queries within the body of another query loop, which means you're opening up lots of connections, which could be slow. I'd reorganize as followd. - Cache the resul

[go-nuts] Golang slow performance inside for loop MySQL Queries

2020-10-20 Thread billyp314
I use Go with github.com/go-sql-driver/mysql to connect to MySQL. The performance in Go vs other languages is terrible or I'm missing something. I use Go for my REST API, an example is below: We have a table with posts. We fetch the posts, on each post we search favorites table (if user has fav