FAQ
I want to simulation a thousands of client request to access postgresql. So
the code:
--------------------------------------------------------------------------------------------------------------------------------------------
func main() {
...
size := 1000
ch := make(chan int, 1)
for i := 0; i < size; i++ {
go func_1(i, db, ch) // a client request process
}

for i := 0; i < size; i++ {
<-ch
}
}

func func_1(name int, db *sql.DB, ch chan int) {
err := db.QueryRow("INSERT INTO t2 (name) VALUES($1) RETURNING id",
name).Scan(&id)
ch <- 1
}
--------------------------------------------------------------------------------------------------------------------------------------------
But usually can only be inserted into the hundreds rows with the error: func_1
error: dial tcp 127.0.0.1:5432: connection timed out

I want to know, pq whether it can support the high-traffic web site? Thanks.




--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Tor Langballe at Mar 6, 2013 at 10:03 am
    ( I assume you mean pq and not pg)

    Shouldn't you be getting:

    "pq: sorry, too many clients already"

    That's what I get when I have more than 20 go-routines writing (and
    possibly reading, not sure) the DB simultaniously,
    since my mac postgresql server has 20 connections as it's max in the config
    file.

    I'm using github.com/bmizerany/pq
    is that the package you are using?

    tor

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Eucal J at Mar 6, 2013 at 10:28 am
    yes, i'm using pq.

    but i changed thed pg conf file, max-connected to 1000, when i start 1000
    go routine, still have this problem.

    在 2013年3月6日星期三UTC+8下午6时03分25秒,Tor Langballe写道:
    ( I assume you mean pq and not pg)

    Shouldn't you be getting:

    "pq: sorry, too many clients already"

    That's what I get when I have more than 20 go-routines writing (and
    possibly reading, not sure) the DB simultaniously,
    since my mac postgresql server has 20 connections as it's max in the
    config file.

    I'm using github.com/bmizerany/pq
    is that the package you are using?

    tor
    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Eucal J at Mar 6, 2013 at 10:31 am
    i changed the postgresql max-connection to 1000, then I run at the same
    time the 1000 go routine to insert into database, but only about 700
    rows inserted successfully, the other show the error timeout.

    在 2013年3月6日星期三UTC+8下午6时28分17秒,Eucal J写道:
    yes, i'm using pq.

    but i changed thed pg conf file, max-connected to 1000, when i start 1000
    go routine, still have this problem.

    在 2013年3月6日星期三UTC+8下午6时03分25秒,Tor Langballe写道:
    ( I assume you mean pq and not pg)

    Shouldn't you be getting:

    "pq: sorry, too many clients already"

    That's what I get when I have more than 20 go-routines writing (and
    possibly reading, not sure) the DB simultaniously,
    since my mac postgresql server has 20 connections as it's max in the
    config file.

    I'm using github.com/bmizerany/pq
    is that the package you are using?

    tor
    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Jim Robinson at Mar 6, 2013 at 2:35 pm

    On Wednesday, March 6, 2013 2:31:21 AM UTC-8, Eucal J wrote:

    i changed the postgresql max-connection to 1000, then I run at the same
    time the 1000 go routine to insert into database, but only about 700
    rows inserted successfully, the other show the error timeout.
    Are you possibly running out of sockets? Often when simulating
    large numbers of clients, default OS settings will run into problems
    where so many sockets are in TIMED_WAIT state that the OS can't
    allocate new ones in time to finish a test.

    A program like netstat would tell you if this was the case. If it is, it
    will usually be possible to raise the number of filehandles available
    or sometimes it makes sense to lower the amount of time a
    socket will spend in TIMED_WAIT.


    Jim

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMar 5, '13 at 11:57a
activeMar 6, '13 at 2:35p
posts5
users3
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase