Re: [go-nuts] how to get file's current offset
On Thu, Apr 18, 2019 at 10:34:24PM +0800, sa517...@mail.ustc.edu.cn wrote: > I want to know file's current read offset after open a file, but I can not > found related API. > > f, err := os.Open("/tmp/") > if err != nil{ > panic(err) > } > > ... // some read operation > > // how can I get f's current read offset?? offset, err := f.Seek(0, io.SeekCurrent) -- Valentin -- 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. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] HTTP client request rate
On Fri, Feb 08, 2019 at 10:12:36PM +0100, Valentin Vidic wrote: > Yes, it is quite strange. I don't see it hitting any limits but > the request rate goes down. Seems it could be GC related since turning off GC gives 5x request rate with 20 gorutines: $ ./gb -duration 15s -parallel 5 http://nginx Running 5 parallel clients for 15s... Requests: 216070 Rate: 14404.7/s Bytes: 132234840 Code[200]: 216070 $ GOGC=off ./gb -duration 15s -parallel 5 http://nginx Running 5 parallel clients for 15s... Requests: 280430 Rate: 18695.3/s Bytes: 171623160 Code[200]: 280430 $ ./gb -duration 15s -parallel 20 http://nginx Running 20 parallel clients for 15s... Requests: 153903 Rate: 10260.2/s Bytes: 94188636 Code[200]: 153903 $ GOGC=off ./gb -duration 15s -parallel 20 http://nginx Running 20 parallel clients for 15s... Requests: 776554 Rate: 51770.3/s Bytes: 475251048 Code[200]: 776554 -- Valentin -- 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. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] HTTP client request rate
On Fri, Feb 08, 2019 at 02:30:52PM -0600, robert engels wrote: > Could be many things, but a few to think about: Yes, it is quite strange. I don't see it hitting any limits but the request rate goes down. > If you run more Go routines than you have CPUs available, and the task > is CPU bound (which may be if the url points to a local resource), > then you are going to thrash, causing worse performance. CPU does not seem to be maxed out, here is the info for 5 gorutines: CPU | sys 98% | user436% | irq 26% | idle 4222% | wait 0% | curf 2.20GHz | curscal ?% | CPL | avg13.28 | avg52.54 | avg15 1.28 | csw 186540 | intr 164257 | | numcpu48 | 541% gb 123% nginx And for 20 gorutines it looks like this: CPU | sys 132% | user970% | irq 21% | idle 3655% | wait 0% | curf 2.20GHz | curscal ?% | CPL | avg10.52 | avg51.18 | avg15 1.01 | csw 240847 | intr 203360 | | numcpu48 | 1170% gb 103% nginx > The service you are calling is not properly concurrent, so the more > simultaneously requests, the worse it performs. The server end is nginx serving a default static page, so it should be quite fast. > You are hitting network/router limits, so it is dropping packets, > causing worse performance due to TCP retries and/or smaller window > sizes. Just tried running client and server on the same host and it gives the same numbers. -- Valentin -- 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. For more options, visit https://groups.google.com/d/optout.
[go-nuts] HTTP client request rate
Hi, Can someone help me figure out why the performance (request rate) of this program goes down when I add more gorutines? $ ./gb -duration 15s -parallel 5 http://nginx Running 5 parallel clients for 15s... Requests: 217998 Rate: 14533.2/s Bytes: 133414776 Code[200]: 217998 $ ./gb -duration 15s -parallel 20 http://nginx Running 20 parallel clients for 15s... Requests: 155150 Rate: 10343.3/s Bytes: 94951800 Code[200]: 155150 -- Valentin -- 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. For more options, visit https://groups.google.com/d/optout. package main import ( "flag" "fmt" "io" "net" "net/http" "os" "runtime" "runtime/pprof" "time" ) type stats struct { req int err int rerr int bytes int code map[int]int } func bench(url string, compress bool, timeout time.Duration, done chan struct{}, result chan stats) { s := stats{} s.code = make(map[int]int) transport := { DisableCompression: !compress, TLSHandshakeTimeout: timeout, DialContext: ({ Timeout: timeout, DualStack: true, }).DialContext, } client := { Transport: transport, Timeout: timeout, } written := 0 buf := make([]byte, 10*1024) LOOP: for { s.req++ resp, err := client.Get(url) if err != nil { fmt.Println(err) s.err++ } else { s.code[resp.StatusCode]++ for { written, err = resp.Body.Read(buf) s.bytes += written if err != nil { break } } if err != nil && err != io.EOF { fmt.Println(err) s.rerr++ } resp.Body.Close() } select { case <-done: break LOOP default: } } result <- s } func main() { var compression = flag.Bool("compression", true, "use HTTP compression") var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file") var duration = flag.Duration("duration", 15*time.Second, "test duration") var memprofile = flag.String("memprofile", "", "write memory profile to file") var parallel = flag.Int("parallel", 20, "number of parallel client connections") var timeout = flag.Duration("timeout", 10*time.Second, "request timeout") flag.Parse() url := flag.Arg(0) if url == "" { fmt.Println("No url given") os.Exit(1) } if *cpuprofile != "" { f, err := os.Create(*cpuprofile) if err != nil { fmt.Println("Could not create cpu profile:", err) os.Exit(1) } pprof.StartCPUProfile(f) defer pprof.StopCPUProfile() } done := make(chan struct{}) result := make(chan stats) fmt.Printf("Running %d parallel clients for %v...\n", *parallel, *duration) for i := 0; i < *parallel; i++ { go bench(url, *compression, *timeout, done, result) } time.Sleep(*duration) close(done) total := stats{} total.code = make(map[int]int) for i := 0; i < *parallel; i++ { s := <-result total.req += s.req total.err += s.err total.rerr += s.rerr total.bytes += s.bytes for k, v := range s.code { total.code[k] += v } } fmt.Println("Requests:", total.req) fmt.Printf("Rate: %.1f/s\n", float64(total.req)/duration.Seconds()) fmt.Println("Bytes:", total.bytes) if total.err > 0 { fmt.Println("Errors:", total.err) } if total.rerr > 0 { fmt.Println("Read errors:", total.rerr) } for k, v := range total.code { fmt.Printf("Code[%d]: %d\n", k, v) } if *memprofile != "" { f, err := os.Create(*memprofile) if err != nil { fmt.Println("Could not create memory profile: ", err) }
Re: [go-nuts] Re: C++ 11 to Golang convertor
On Thu, Jan 03, 2019 at 02:46:39PM -0800, Eric Raymond wrote: > On the other hand, I believe graceful, comment-preserving C to idiomatic-Go > transpilation is almost possible. By 'almost' I mean that the tool would > pass through a small enough percentage of untranslated residuals for > corrections to be around a 5% job for a human expert. > > I've had a lot of incentive to think about this because my concerns center > around vast masses of C infrastructure code in critical network services > like NTP, DNS, etc. The security and reliability consequences of unsafe > code in that swamp are serious and it needs to be drained. Transpilation > to golang is, I think, the first realistic hope we've had of doing that > without a prohibitively high labor input. > > By possible I do not mean easy. I've scoped the job and done a design > sketch. I think my qualifications for writing such a transpiler are > exceptionally good, but it would nevertheless take me a minimum of two > years of hard work to get there. I have put put some feelers for > funding; if I get to choose my next major project after NTPsec, this would > be it. Golang compiler was converted from C to Go in some version, but I don't know if the tool used there is available somewhere. -- Valentin -- 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. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] How to send a POST request from http.Redirect?
On Fri, Oct 27, 2017 at 09:04:25PM -0700, hkang.sun...@gmail.com wrote: > I have a question about sending POST request through the http.Redirect > function. > The following is my http handler function. In this function, I get some > secret data and want to pass the data to the redirectURL. > I could not use GET with query parameter because the secret data is > explicit as a query in a GET redirect URL. So I am thinking sending the > data in the body of a POST request. > > func myHandler (w http.ResponseWriter, r *HTTPRequest) { > // process and get some secret data > data := someValue > http.Redirect(w, r, redirectURL, http.StatusFound) > } > > I tried setting "r.Method="POST""; however it does not work. > Could anyone help on this? Thanks. in advance. Try if using http.StatusTemporaryRedirect instead of http.StatusFound works better: StatusTemporaryRedirect = 307 // RFC 7231, 6.4.7 -- Valentin -- 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. For more options, visit https://groups.google.com/d/optout.