FAQ

I'm stressing my local servre with:

r, err := http.NewRequest("POST", "http://localhost:12345", &buff)
if err != nil {
return err
}
_, err := http.DefaultClient.Do(r)
I run this in a loop, single goroutine, my sever response really well until
few thousand requests.
I got this error message:
accept tcp [::]:12345: too many open files

*The first attempt*: I think I need to clouse the reponse body any way:
...
...

resp, err := http.DefaultClient.Do(r)
if err == nil {
defer resp.Body.Close()
}
  Still got the issue.

  *The second attempt*: I give notice about the keep-alive option, I try:
tr := &http.Transport{
DisableKeepAlives: true,
DisableCompression: true, // this line just for fun
}
client := &http.Client{Transport: tr}
r, err := http.NewRequest("POST", "http://localhost:12345", &buff)
if err != nil {
return err
}
_, err := client.Do(r)
Not any good news! I check with netstat and see alot of tcp connection
still option in 12345

*Finally* I think I should try them both:
tr := &http.Transport{
DisableKeepAlives: true,
DisableCompression: true, // this line just for fun
}
client := &http.Client{Transport: tr}
r, err := http.NewRequest("POST", "http://localhost:12345", &buff)
if err != nil {
return err
}
resp, err := client.Do(r)
if err == nil {
defer resp.Body.Close()
}
And yay, its work!
I don't really understand what is going on, becuase I think "keep-alive"
whill help me reduce the "open files"?

--
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/d/optout.

Search Discussions

  • Aaron Cannon at May 22, 2015 at 8:52 pm
    Is this code inside a function, or directly inside a loop? If inside
    a loop, then the connections will not be closed until at least after
    the loop terminates.

    Otherwise, not sure about your question.

    Aaron
    On 5/22/15, nvcnvn wrote:
    I'm stressing my local servre with:
    r, err := http.NewRequest("POST", "http://localhost:12345", &buff)
    if err != nil {
    return err
    }
    _, err := http.DefaultClient.Do(r)
    I run this in a loop, single goroutine, my sever response really well until

    few thousand requests.
    I got this error message:
    accept tcp [::]:12345: too many open files

    *The first attempt*: I think I need to clouse the reponse body any way:
    ...
    ...

    resp, err := http.DefaultClient.Do(r)
    if err == nil {
    defer resp.Body.Close()
    }
    Still got the issue.

    *The second attempt*: I give notice about the keep-alive option, I try:
    tr := &http.Transport{
    DisableKeepAlives: true,
    DisableCompression: true, // this line just for fun
    }
    client := &http.Client{Transport: tr}
    r, err := http.NewRequest("POST", "http://localhost:12345", &buff)
    if err != nil {
    return err
    }
    _, err := client.Do(r)
    Not any good news! I check with netstat and see alot of tcp connection
    still option in 12345

    *Finally* I think I should try them both:
    tr := &http.Transport{
    DisableKeepAlives: true,
    DisableCompression: true, // this line just for fun
    }
    client := &http.Client{Transport: tr}
    r, err := http.NewRequest("POST", "http://localhost:12345", &buff)
    if err != nil {
    return err
    }
    resp, err := client.Do(r)
    if err == nil {
    defer resp.Body.Close()
    }
    And yay, its work!
    I don't really understand what is going on, becuase I think "keep-alive"
    whill help me reduce the "open files"?

    --
    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/d/optout.
    --
    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/d/optout.
  • Nvcnvn at May 23, 2015 at 12:45 am
    Hi Aaron, thanks for you reply.
    In short, my question is:
    Why DisableKeepAlives help, when I think it should not help at all?
    On Saturday, May 23, 2015 at 3:52:29 AM UTC+7, Aaron Cannon wrote:

    Is this code inside a function, or directly inside a loop? If inside
    a loop, then the connections will not be closed until at least after
    the loop terminates.

    Otherwise, not sure about your question.

    Aaron
    On 5/22/15, nvcnvn <nvc...@gmail.com <javascript:>> wrote:
    I'm stressing my local servre with:
    r, err := http.NewRequest("POST", "http://localhost:12345", &buff)
    if err != nil {
    return err
    }
    _, err := http.DefaultClient.Do(r)
    I run this in a loop, single goroutine, my sever response really well until
    few thousand requests.
    I got this error message:
    accept tcp [::]:12345: too many open files

    *The first attempt*: I think I need to clouse the reponse body any way:
    ...
    ...

    resp, err := http.DefaultClient.Do(r)
    if err == nil {
    defer resp.Body.Close()
    }
    Still got the issue.

    *The second attempt*: I give notice about the keep-alive option, I try:
    tr := &http.Transport{
    DisableKeepAlives: true,
    DisableCompression: true, // this line just for fun
    }
    client := &http.Client{Transport: tr}
    r, err := http.NewRequest("POST", "http://localhost:12345", &buff)
    if err != nil {
    return err
    }
    _, err := client.Do(r)
    Not any good news! I check with netstat and see alot of tcp connection
    still option in 12345

    *Finally* I think I should try them both:
    tr := &http.Transport{
    DisableKeepAlives: true,
    DisableCompression: true, // this line just for fun
    }
    client := &http.Client{Transport: tr}
    r, err := http.NewRequest("POST", "http://localhost:12345", &buff)
    if err != nil {
    return err
    }
    resp, err := client.Do(r)
    if err == nil {
    defer resp.Body.Close()
    }
    And yay, its work!
    I don't really understand what is going on, becuase I think "keep-alive"
    whill help me reduce the "open files"?

    --
    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...@googlegroups.com <javascript:>.
    For more options, visit https://groups.google.com/d/optout.
    --
    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/d/optout.
  • Jeffrey 'jf' Lim at May 23, 2015 at 12:57 am

    On Sat, May 23, 2015 at 8:45 AM, nvcnvn wrote:

    Hi Aaron, thanks for you reply.
    In short, my question is:
    Why DisableKeepAlives help, when I think it should not help at all?
    As per Aaron's point, your connections will not close until the *function
    exits. Using the defer, your connections will only keep racking up until
    the goroutine exits.

    Keep-alive enables you to reuse the same connection for multiple requests,
    cutting down on the number of open connections to the server.

    -jf


    On Saturday, May 23, 2015 at 3:52:29 AM UTC+7, Aaron Cannon wrote:

    Is this code inside a function, or directly inside a loop? If inside
    a loop, then the connections will not be closed until at least after
    the loop terminates.

    Otherwise, not sure about your question.

    Aaron
    On 5/22/15, nvcnvn wrote:
    I'm stressing my local servre with:
    r, err := http.NewRequest("POST", "http://localhost:12345", &buff)
    if err != nil {
    return err
    }
    _, err := http.DefaultClient.Do(r)
    I run this in a loop, single goroutine, my sever response really well until
    few thousand requests.
    I got this error message:
    accept tcp [::]:12345: too many open files

    *The first attempt*: I think I need to clouse the reponse body any way:
    ...
    ...

    resp, err := http.DefaultClient.Do(r)
    if err == nil {
    defer resp.Body.Close()
    }
    Still got the issue.

    *The second attempt*: I give notice about the keep-alive option, I
    try:
    tr := &http.Transport{
    DisableKeepAlives: true,
    DisableCompression: true, // this line just for fun
    }
    client := &http.Client{Transport: tr}
    r, err := http.NewRequest("POST", "http://localhost:12345", &buff)
    if err != nil {
    return err
    }
    _, err := client.Do(r)
    Not any good news! I check with netstat and see alot of tcp connection
    still option in 12345

    *Finally* I think I should try them both:
    tr := &http.Transport{
    DisableKeepAlives: true,
    DisableCompression: true, // this line just for fun
    }
    client := &http.Client{Transport: tr}
    r, err := http.NewRequest("POST", "http://localhost:12345", &buff)
    if err != nil {
    return err
    }
    resp, err := client.Do(r)
    if err == nil {
    defer resp.Body.Close()
    }
    And yay, its work!
    I don't really understand what is going on, becuase I think
    "keep-alive"
    whill help me reduce the "open files"?

    --
    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...@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    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/d/optout.
    --
    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/d/optout.
  • Lars Tørnes Hansen at May 23, 2015 at 4:05 pm
    I think you had ran out of available file descriptors.

    Just increase the amount of available system-wide file descriptors first,
    and then increase the amount of available file descriptors for the program
    and/or the user that starts the program:

    Assuming you are using a Linux based operating system:
    http://www.cyberciti.biz/faq/linux-increase-the-maximum-number-of-open-files/

    /Lars

    Den fredag den 22. maj 2015 kl. 17.38.57 UTC+2 skrev nvcnvn:
    I'm stressing my local servre with:
    r, err := http.NewRequest("POST", "http://localhost:12345", &buff)
    if err != nil {
    return err
    }
    _, err := http.DefaultClient.Do(r)
    I run this in a loop, single goroutine, my sever response really well
    until few thousand requests.
    I got this error message:
    accept tcp [::]:12345: too many open files

    *The first attempt*: I think I need to clouse the reponse body any way:
    ...
    ...

    resp, err := http.DefaultClient.Do(r)
    if err == nil {
    defer resp.Body.Close()
    }
    Still got the issue.

    *The second attempt*: I give notice about the keep-alive option, I try:
    tr := &http.Transport{
    DisableKeepAlives: true,
    DisableCompression: true, // this line just for fun
    }
    client := &http.Client{Transport: tr}
    r, err := http.NewRequest("POST", "http://localhost:12345", &buff)
    if err != nil {
    return err
    }
    _, err := client.Do(r)
    Not any good news! I check with netstat and see alot of tcp connection
    still option in 12345

    *Finally* I think I should try them both:
    tr := &http.Transport{
    DisableKeepAlives: true,
    DisableCompression: true, // this line just for fun
    }
    client := &http.Client{Transport: tr}
    r, err := http.NewRequest("POST", "http://localhost:12345", &buff)
    if err != nil {
    return err
    }
    resp, err := client.Do(r)
    if err == nil {
    defer resp.Body.Close()
    }
    And yay, its work!
    I don't really understand what is going on, becuase I think "keep-alive"
    whill help me reduce the "open files"?
    --
    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/d/optout.
  • Justin Israel at May 23, 2015 at 7:52 pm

    On Sun, May 24, 2015 at 4:05 AM Lars Tørnes Hansen wrote:

    I think you had ran out of available file descriptors.

    Just increase the amount of available system-wide file descriptors first,
    and then increase the amount of available file descriptors for the program
    and/or the user that starts the program:
    The problem that was listed didn't strike me as something that should be
    solved by just increasing the file descriptors (maybe I am wrong). It
    seemed like a design issue that is not closing them as fast as intended. I
    would think increasing the fd limit would just allow it to propagate the
    problem even further, before failing again.

    Assuming you are using a Linux based operating system:

    http://www.cyberciti.biz/faq/linux-increase-the-maximum-number-of-open-files/

    /Lars

    Den fredag den 22. maj 2015 kl. 17.38.57 UTC+2 skrev nvcnvn:
    I'm stressing my local servre with:
    r, err := http.NewRequest("POST", "http://localhost:12345", &buff)
    if err != nil {
    return err
    }
    _, err := http.DefaultClient.Do(r)
    I run this in a loop, single goroutine, my sever response really well
    until few thousand requests.
    I got this error message:
    accept tcp [::]:12345: too many open files

    *The first attempt*: I think I need to clouse the reponse body any way:
    ...
    ...

    resp, err := http.DefaultClient.Do(r)
    if err == nil {
    defer resp.Body.Close()
    }
    Still got the issue.

    *The second attempt*: I give notice about the keep-alive option, I try:
    tr := &http.Transport{
    DisableKeepAlives: true,
    DisableCompression: true, // this line just for fun
    }
    client := &http.Client{Transport: tr}
    r, err := http.NewRequest("POST", "http://localhost:12345", &buff)
    if err != nil {
    return err
    }
    _, err := client.Do(r)
    Not any good news! I check with netstat and see alot of tcp connection
    still option in 12345

    *Finally* I think I should try them both:
    tr := &http.Transport{
    DisableKeepAlives: true,
    DisableCompression: true, // this line just for fun
    }
    client := &http.Client{Transport: tr}
    r, err := http.NewRequest("POST", "http://localhost:12345", &buff)
    if err != nil {
    return err
    }
    resp, err := client.Do(r)
    if err == nil {
    defer resp.Body.Close()
    }
    And yay, its work!
    I don't really understand what is going on, becuase I think "keep-alive"
    whill help me reduce the "open files"?
    --
    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/d/optout.
    --
    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/d/optout.
  • Jakob Borg at May 24, 2015 at 12:06 pm
    I think this is https://github.com/golang/go/issues/6785. I regularly run
    into this when trying to for example benchmark local HTTP calls, even with
    keepalives disabled and immediate resp.Body.Close() calls. I've worked
    around it in some cases by simply not using the net/http package and doing
    it myself at the socket level, but it's painful and annoying and imho
    shouldn't really be necessary...

    2015-05-23 21:51 GMT+02:00 Justin Israel <justinisrael@gmail.com>:
    On Sun, May 24, 2015 at 4:05 AM Lars Tørnes Hansen wrote:

    I think you had ran out of available file descriptors.

    Just increase the amount of available system-wide file descriptors first,
    and then increase the amount of available file descriptors for the program
    and/or the user that starts the program:
    The problem that was listed didn't strike me as something that should be
    solved by just increasing the file descriptors (maybe I am wrong). It
    seemed like a design issue that is not closing them as fast as intended. I
    would think increasing the fd limit would just allow it to propagate the
    problem even further, before failing again.

    Assuming you are using a Linux based operating system:

    http://www.cyberciti.biz/faq/linux-increase-the-maximum-number-of-open-files/

    /Lars

    Den fredag den 22. maj 2015 kl. 17.38.57 UTC+2 skrev nvcnvn:
    I'm stressing my local servre with:
    r, err := http.NewRequest("POST", "http://localhost:12345", &buff)
    if err != nil {
    return err
    }
    _, err := http.DefaultClient.Do(r)
    I run this in a loop, single goroutine, my sever response really well
    until few thousand requests.
    I got this error message:
    accept tcp [::]:12345: too many open files

    *The first attempt*: I think I need to clouse the reponse body any way:
    ...
    ...

    resp, err := http.DefaultClient.Do(r)
    if err == nil {
    defer resp.Body.Close()
    }
    Still got the issue.

    *The second attempt*: I give notice about the keep-alive option, I try:
    tr := &http.Transport{
    DisableKeepAlives: true,
    DisableCompression: true, // this line just for fun
    }
    client := &http.Client{Transport: tr}
    r, err := http.NewRequest("POST", "http://localhost:12345", &buff)
    if err != nil {
    return err
    }
    _, err := client.Do(r)
    Not any good news! I check with netstat and see alot of tcp connection
    still option in 12345

    *Finally* I think I should try them both:
    tr := &http.Transport{
    DisableKeepAlives: true,
    DisableCompression: true, // this line just for fun
    }
    client := &http.Client{Transport: tr}
    r, err := http.NewRequest("POST", "http://localhost:12345", &buff)
    if err != nil {
    return err
    }
    resp, err := client.Do(r)
    if err == nil {
    defer resp.Body.Close()
    }
    And yay, its work!
    I don't really understand what is going on, becuase I think "keep-alive"
    whill help me reduce the "open files"?
    --
    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/d/optout.
    --
    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/d/optout.
    --
    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/d/optout.
  • Jakob Borg at May 24, 2015 at 12:58 pm
    Actually, a small retraction on that. While trying to reproduce it now, I
    find that things mostly work for normal requests as long as the response is
    actually read. If the response body is just closed, keepalives obviously
    don't work as intended and in the non-keepalive case you can run into not
    being able to allocate new sockets - probably due to lingering closes...

    //jb

    2015-05-24 14:06 GMT+02:00 Jakob Borg <jakob@nym.se>:
    I think this is https://github.com/golang/go/issues/6785. I regularly run
    into this when trying to for example benchmark local HTTP calls, even with
    keepalives disabled and immediate resp.Body.Close() calls. I've worked
    around it in some cases by simply not using the net/http package and doing
    it myself at the socket level, but it's painful and annoying and imho
    shouldn't really be necessary...

    2015-05-23 21:51 GMT+02:00 Justin Israel <justinisrael@gmail.com>:

    On Sun, May 24, 2015 at 4:05 AM Lars Tørnes Hansen <larsth@gmail.com>
    wrote:
    I think you had ran out of available file descriptors.

    Just increase the amount of available system-wide file descriptors
    first, and then increase the amount of available file descriptors for the
    program and/or the user that starts the program:
    The problem that was listed didn't strike me as something that should be
    solved by just increasing the file descriptors (maybe I am wrong). It
    seemed like a design issue that is not closing them as fast as intended. I
    would think increasing the fd limit would just allow it to propagate the
    problem even further, before failing again.

    Assuming you are using a Linux based operating system:

    http://www.cyberciti.biz/faq/linux-increase-the-maximum-number-of-open-files/

    /Lars

    Den fredag den 22. maj 2015 kl. 17.38.57 UTC+2 skrev nvcnvn:
    I'm stressing my local servre with:
    r, err := http.NewRequest("POST", "http://localhost:12345", &buff)
    if err != nil {
    return err
    }
    _, err := http.DefaultClient.Do(r)
    I run this in a loop, single goroutine, my sever response really well
    until few thousand requests.
    I got this error message:
    accept tcp [::]:12345: too many open files

    *The first attempt*: I think I need to clouse the reponse body any way:
    ...
    ...

    resp, err := http.DefaultClient.Do(r)
    if err == nil {
    defer resp.Body.Close()
    }
    Still got the issue.

    *The second attempt*: I give notice about the keep-alive option, I
    try:
    tr := &http.Transport{
    DisableKeepAlives: true,
    DisableCompression: true, // this line just for fun
    }
    client := &http.Client{Transport: tr}
    r, err := http.NewRequest("POST", "http://localhost:12345", &buff)
    if err != nil {
    return err
    }
    _, err := client.Do(r)
    Not any good news! I check with netstat and see alot of tcp connection
    still option in 12345

    *Finally* I think I should try them both:
    tr := &http.Transport{
    DisableKeepAlives: true,
    DisableCompression: true, // this line just for fun
    }
    client := &http.Client{Transport: tr}
    r, err := http.NewRequest("POST", "http://localhost:12345", &buff)
    if err != nil {
    return err
    }
    resp, err := client.Do(r)
    if err == nil {
    defer resp.Body.Close()
    }
    And yay, its work!
    I don't really understand what is going on, becuase I think
    "keep-alive" whill help me reduce the "open files"?
    --
    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/d/optout.
    --
    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/d/optout.
    --
    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/d/optout.
  • Nguyễn Văn Cao Nguyên at May 24, 2015 at 2:10 pm
    Yep, you're right!
    My friend show me that I should dry the body by:
    io.Copy(ioutil.Discard, res.Body)
    On Sun, May 24, 2015 at 7:58 PM, Jakob Borg wrote:

    Actually, a small retraction on that. While trying to reproduce it now, I
    find that things mostly work for normal requests as long as the response is
    actually read. If the response body is just closed, keepalives obviously
    don't work as intended and in the non-keepalive case you can run into not
    being able to allocate new sockets - probably due to lingering closes...

    //jb

    2015-05-24 14:06 GMT+02:00 Jakob Borg <jakob@nym.se>:
    I think this is https://github.com/golang/go/issues/6785. I regularly
    run into this when trying to for example benchmark local HTTP calls, even
    with keepalives disabled and immediate resp.Body.Close() calls. I've worked
    around it in some cases by simply not using the net/http package and doing
    it myself at the socket level, but it's painful and annoying and imho
    shouldn't really be necessary...

    2015-05-23 21:51 GMT+02:00 Justin Israel <justinisrael@gmail.com>:

    On Sun, May 24, 2015 at 4:05 AM Lars Tørnes Hansen <larsth@gmail.com>
    wrote:
    I think you had ran out of available file descriptors.

    Just increase the amount of available system-wide file descriptors
    first, and then increase the amount of available file descriptors for the
    program and/or the user that starts the program:
    The problem that was listed didn't strike me as something that should be
    solved by just increasing the file descriptors (maybe I am wrong). It
    seemed like a design issue that is not closing them as fast as intended. I
    would think increasing the fd limit would just allow it to propagate the
    problem even further, before failing again.

    Assuming you are using a Linux based operating system:

    http://www.cyberciti.biz/faq/linux-increase-the-maximum-number-of-open-files/

    /Lars

    Den fredag den 22. maj 2015 kl. 17.38.57 UTC+2 skrev nvcnvn:
    I'm stressing my local servre with:
    r, err := http.NewRequest("POST", "http://localhost:12345", &buff)
    if err != nil {
    return err
    }
    _, err := http.DefaultClient.Do(r)
    I run this in a loop, single goroutine, my sever response really well
    until few thousand requests.
    I got this error message:
    accept tcp [::]:12345: too many open files

    *The first attempt*: I think I need to clouse the reponse body any
    way:
    ...
    ...

    resp, err := http.DefaultClient.Do(r)
    if err == nil {
    defer resp.Body.Close()
    }
    Still got the issue.

    *The second attempt*: I give notice about the keep-alive option, I
    try:
    tr := &http.Transport{
    DisableKeepAlives: true,
    DisableCompression: true, // this line just for fun
    }
    client := &http.Client{Transport: tr}
    r, err := http.NewRequest("POST", "http://localhost:12345", &buff)
    if err != nil {
    return err
    }
    _, err := client.Do(r)
    Not any good news! I check with netstat and see alot of tcp connection
    still option in 12345

    *Finally* I think I should try them both:
    tr := &http.Transport{
    DisableKeepAlives: true,
    DisableCompression: true, // this line just for fun
    }
    client := &http.Client{Transport: tr}
    r, err := http.NewRequest("POST", "http://localhost:12345", &buff)
    if err != nil {
    return err
    }
    resp, err := client.Do(r)
    if err == nil {
    defer resp.Body.Close()
    }
    And yay, its work!
    I don't really understand what is going on, becuase I think
    "keep-alive" whill help me reduce the "open files"?
    --
    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/d/optout.
    --
    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/d/optout.
    --
    You received this message because you are subscribed to a topic in the
    Google Groups "golang-nuts" group.
    To unsubscribe from this topic, visit
    https://groups.google.com/d/topic/golang-nuts/jKhdc8ZB1qM/unsubscribe.
    To unsubscribe from this group and all its topics, send an email to
    golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.


    --
    *Nguyễn Văn Cao Nguyên*
         /**
          * Contact : +84+935704595
          * Blog : http://nguyen.open-vn.org
          */

    --
    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/d/optout.
  • Benjamin Measures at May 24, 2015 at 2:58 pm

    On Sunday, 24 May 2015 15:11:05 UTC+1, nvcnvn wrote:
    I should dry the body by:
    io.Copy(ioutil.Discard, res.Body)
    Closing response body used to drain but caused unpredictable delays closing
    connections. Burden shifted onto clients to decide:
    https://github.com/golang/go/issues/3672

    Documented in Go 1.5:
    https://github.com/golang/go/issues/5645

    --
    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/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMay 22, '15 at 3:39p
activeMay 24, '15 at 2:58p
posts10
users7
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase