[go-nuts] Experience using Go for a student projet

2017-07-29 Thread Juliusz Chroboczek
Dear all, I've just finished supervising three fourth year students doing a month-long summer project in Go. I thought some of you might be interested in my conclusions. The students were decent C programmers but had more experience with Java (and I am not an experienced Go programmer myself).

[go-nuts] Re: Experience using Go for a student projet

2017-08-01 Thread Juliusz Chroboczek
> suggests you should move the wg.Add(1) out of the Goroutine from here: [...] > to there Thanks, that's an actual bug. > * Do you happen to know about the context package? It seems like a lot of > the closedown can happen if you recast part of the system as contexts and > cancel those

[go-nuts] Re: bufio.Scanner and partial reads

2017-07-09 Thread Juliusz Chroboczek
>> Do I have a guarantee that the final \n will be passed to my custom >> scan function and the result passed to the Scan function even if the >> connection hangs just after the \n? > Yes (assuming the underlying Reader returns the final \n). >> Do similar properties hold for bufio.Reader (i.e.,

[go-nuts] bufio.Scanner and partial reads

2017-07-09 Thread Juliusz Chroboczek
Hi, I cannot find anything in the documentation about how bufio.Scanner behaves when the underlying io.Reader does partial reads. I'm using a Scanner to parse a stream of tokens that arrives over a TCP socket. The stream is a sequence of lines terminated by \n. Do I have a guarantee that the

[go-nuts] Re: Experience using Go for a student projet

2017-07-30 Thread Juliusz Chroboczek
> How did your students adjust to working with the GOPATH? No issue at all. I told them to create a directory under ~/go/src, and that was it. > It seems to cause some people trouble. In my experience, undergraduate students accept pretty much anything if the instructions you give them are

[go-nuts] Re: Experience using Go for a student projet

2017-07-30 Thread Juliusz Chroboczek
> I glanced at babelweb2 (https://github.com/Vivena/babelweb2/). A code > review would be useful. For example, from parser/parser.go: Thanks for the review. As I've mentioned, neither the students nor me had any significant experience with Go, so we were learning as we went along. If you

[go-nuts] Latency profiling

2017-09-17 Thread Juliusz Chroboczek
Hi, I've got a CPU-bound function that is not called very frequently, and hence doesn't appear prominently in the CPU profile, but I'm guessing that it takes a significant time to run (on the order of tens of milliseconds), and hence increases the latency of the calling goroutine. I don't see

[go-nuts] Re: bufio.Writer and timeouts

2017-09-14 Thread Juliusz Chroboczek
> Is extending the deadline right before flushing an option? No. Before the Flush (or the Write) times out, I don't know that this particular peer is congested, and hence I have no reason to reschedule requests queued to this peer on a different connection. -- Juliusz -- You received this

[go-nuts] Re: bufio.Writer and timeouts

2017-09-14 Thread Juliusz Chroboczek
> Hmm maybe I misunderstood your use case. I thought you were basically > setting a fixed write duration via SetWriteDeadline() before each Write() > call, in which case the same treatment probably should be done for Flush(). I'm already doing that. -- You received this message because you are

[go-nuts] Re: bufio.Writer and timeouts

2017-09-09 Thread Juliusz Chroboczek
> bufio.Writer is about 200 lines, and you probably don't even need all > of them. Just copy it and modify it for your purposes. Ok, thanks. -- Juliusz -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop

[go-nuts] bufio.Writer and timeouts

2017-09-09 Thread Juliusz Chroboczek
Hi, I've got a bufio.Writer which is wrapping a net.TCPConn. Once in a while, Flush() will trigger a write timeout (set with SetWriteDeadline on the underlying connection), in which case I'd like to reschedule some requests on a different connection, and then restart the Flush() with a more

[go-nuts] defer go [was: A few go 2 suggestions]

2017-10-10 Thread Juliusz Chroboczek
> 1. "defer go" extend defers to work on goroutine exit with mechanism just > like defer, but if we say "defer go f()" > instead of "defer f()" then we run on goroutine exit. Very big gains for > scaling here IMHO. If I read the language specification right, goroutines have no identity: a

[go-nuts] Do closures cons?

2017-10-17 Thread Juliusz Chroboczek
I was about to do something like that: var p *P ... otherpackage.f(func(data []byte) { a := p.x + p.y * 42 + p.someothercomplicatedstuff p.g(data, a) } (Yeah, I know. I dislike callbacks too, but I'm pretty much stuck in this particular case since Go doesn't do

[go-nuts] Re: Do closures cons?

2017-10-17 Thread Juliusz Chroboczek
> A method value, on the other hand, will allocate memory in some cases, > as it may need to hold a copy of the value whose method will be > invoked. Even if the method takes a pointer receiver? -- Juliusz -- You received this message because you are subscribed to the Google Groups

[go-nuts] Implementing futures with channels [was: How to pass a value...]

2017-10-17 Thread Juliusz Chroboczek
> The answer depends on whether you have just one value or many. For a single > value (sometimes known as a "future"), I tend to pair a chan of struct{} > with a value to be set. To make the value available, set it, then close the > channel. Readers wait on the channel, then read the value.

[go-nuts] Re: Do closures cons?

2017-10-17 Thread Juliusz Chroboczek
> Depends on what your profiling is telling you. The trouble is -- I have no idea what is the impact of small allocations. I've managed to eliminate most useless large allocations (the amount of data consed used to be twice the amount of data processed, it's now on the order of 103%), which has

[go-nuts] Re: afpacket does not get GRE tunneled packets?

2017-10-18 Thread Juliusz Chroboczek
This is not Go-specific, I hope I'm not breaking some unwritten rule by replying. > I just figured this out. I need to manually set the NIC to promiscuous > mode. > Now the question is, is there a way to set the NIC to promiscuous mode > in code, like in pcap.openlive? You want to call

[go-nuts] Re: Panic recovery and mutex lock question

2017-10-18 Thread Juliusz Chroboczek
> I guess I dont understand why you would want the lock entirely for the > entire execution of the function until the defer. You can get the effect of block-scoped defers by using a local anonymous function: func f(a *A) { func() { a.mu.Lock() defer

[go-nuts] Running a Go server in a chroot

2017-10-23 Thread Juliusz Chroboczek
Hi, I'm running a statically linked (CGO_ENABLED=0) Go network server in a chroot under Linux. The chroot is completely empty (except for the server's data files), yet, to my surprise, the only issue I'm seeing is that the timezone is wrong. So two questions, perhaps three: 1. Which file(s)

[go-nuts] Sanitising a UTF-8 string

2017-10-22 Thread Juliusz Chroboczek
I'm probably missing something obvious, but I've looked through the standard library to no avail. How do I sanitise a []byte to make sure it's a UTF-8 string by replacing all incorrect sequences by the replacement character (or whatever)? I've found unicode/utf8.Valid, which tells me if a []byte

[go-nuts] Re: f*ck you, golang

2017-11-23 Thread Juliusz Chroboczek
> I was meant to be a successful C++/Java programmer, now that is ruined > forever. [...] > My life is ruined and it's on you. You can only blame yourself. You should have studied for the exam rather than doing extra-curricular stuff. -- You received this message because you are subscribed

[go-nuts] Re: Running a Go server in a chroot

2017-10-24 Thread Juliusz Chroboczek
> you need /usr/local/go/lib/time/zoneinfo.zip. time.LoadLocation is using > it. Also /usr/local/go/lib/time/ has a script to refresh timezones. It turns out that copying /etc/localtime into the chroot was enough. Thanks to the person who helped me by private mail (he'll know who he is). --

[go-nuts] Re: Go memory usage

2017-10-24 Thread Juliusz Chroboczek
> It depends entirely on your program. The simplest way to think about > it is that the runtime imposes an overhead on the memory that your > program allocates for its own data structures. If you think of that > overhead as 10%, you won't be very far wrong. How does that fit with GOGC being

[go-nuts] Re: Go memory usage

2017-10-24 Thread Juliusz Chroboczek
> It depends entirely on your program. The simplest way to think about > it is that the runtime imposes an overhead on the memory that your > program allocates for its own data structures. If you think of that > overhead as 10%, you won't be very far wrong. How does that fit with GOGC being

[go-nuts] Re: slice of pointer of struct vs slice of struct

2017-10-21 Thread Juliusz Chroboczek
> I have started to use non pointer slices much more as of late. > Every time I bother measuring it is always faster and it is better for the > GC (usually, caveats apply). So do I. I was just pointing out a caveat that tripped me a couple times. > It also, perhaps naively, feels safer... :)

[go-nuts] Re: I don't know about callbacks in Golang

2018-05-06 Thread Juliusz Chroboczek
> Callbacks are rarely used in Go's ecosystem. https://golang.org/pkg/sort/#Slice https://golang.org/pkg/sync/#Map.Range -- 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

[go-nuts] Re: Does the CanSet and CanAddr methods of a reflect.Value always return the same result?

2018-05-13 Thread Juliusz Chroboczek
>> https://play.golang.org/p/f_qy1ZI56w7 > Got it, thanks. It took me a while. I think the point Ian is making is that an unexported field is not CanSet. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and

Re: [go-nuts] Cgo: using syscall.Select

2018-05-17 Thread Juliusz Chroboczek
> If you do this in Go, you should use golang.org/x/sys/unix package > rather than the syscall package. What's the advantage? (In this particular case, not in general.) > But since you have to call C anyhow, I would suggest just doing it in C. Yeah, I guess it's simpler. > There isn't any way

[go-nuts] Cgo: using syscall.Select

2018-05-16 Thread Juliusz Chroboczek
I'm interfacing with a C library that expects to do its own I/O, but wants to be called after a file descriptor is ready for read. My code currently looks roughly like this: var fdset syscall.FdSet var bits = unsafe.Sizeof(fdset.Bits[0]) * 8 fdset.Bits[uintptr(fd)/bits] |= (1 << (fd

[go-nuts] Re: Cgo: using syscall.Select

2018-05-18 Thread Juliusz Chroboczek
> You could also take a look > at https://godoc.org/github.com/mailru/easygo/netpoll I don't have a net.Conn, just a raw file descriptor. -- Juliusz -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop

[go-nuts] Re: slice of pointer of struct vs slice of struct

2017-10-20 Thread Juliusz Chroboczek
>> What size of T affects is appending/inserting/deleting items to/from >> the slice. If one passes around a value of type []T, those operations >> are probably performed on the value. > On the flip side, []*T will be less cache/TLB/GC friendly than > []T, unless T is much larger than a ptr. On

[go-nuts] Re: net.Pipe doesn't support deadlines

2018-02-04 Thread Juliusz Chroboczek
> Which version of Go are you using? 1.9.3. > https://github.com/golang/go/blob/master/src/net/pipe.go#L224 Excellent, thanks. (In case anyone is interested -- wrapping net.Pipe in order to avoid the errors took all of five minutes.) -- You received this message because you are subscribed to

[go-nuts] net.Pipe doesn't support deadlines

2018-02-03 Thread Juliusz Chroboczek
In net/pipe.go, there's this code: func (p *pipe) SetReadDeadline(t time.Time) error { return {...} } This breaks my code, which uses timeouts and dutifully checks for errors. I guess I have three solutions: 1. remove the error checking in my code; 2. wrap net.Pipe

[go-nuts] About golang.org/x/net/prox and cancellation

2018-02-05 Thread Juliusz Chroboczek
Hi, I'm using golang.org/x/net/proxy, and I've run into an issue: there appears to be no way to cancel a (*proxy.Dialer).Dial in progress -- unlike net.Dialer, there is no DialContext method for proxy.Dialer. Any idea for a workaround? (By the way, since net.Dial is a struct, not an interface,

[go-nuts] Okay to use mmap ?

2018-02-12 Thread Juliusz Chroboczek
Hi, Is it okay to use syscall.Mmap to allocate large amounts of memory, or will it conflict with Go's memory allocator? -- Juliusz -- 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

[go-nuts] Re: About golang.org/x/net/prox and cancellation

2018-02-07 Thread Juliusz Chroboczek
> unlike net.Dialer, there is no DialContext method for proxy.Dialer. That turns out to be issue #19354. -- 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

[go-nuts] Re: Go on MIPS32

2018-02-15 Thread Juliusz Chroboczek
> cgo is not go. The speed of system calls is similar though -- 110 microseconds for a UDP send/receive pair over loopback. As compared to a single core of a 2.4GHz laptop, the MIPS nodes are: - 10 to 20 times slower on integer code; - 30 times slower on small UDP packets over loopback;

[go-nuts] Go on MIPS32

2018-02-15 Thread Juliusz Chroboczek
BenchmarkGoCall 29.00 ns/op BenchmarkCgoCall 100 2302 ns/op 2 microseconds to call into C. Ouch. (That's on a 680MHz 24Kc core with 32kB data cache. I'm not complaining, merely noticing.) -- You received this message because you are

[go-nuts] Re: Cannot take the adress of.....

2018-02-27 Thread Juliusz Chroboczek
> You can't take the address of the return value of a function or a > conversion (which is conceptually just a function) because it doesn't > have a location in memory and thus doesn't have an address. I've never understood the reason for this limitation. I'd expect the compiler to box any value

[go-nuts] Re: Tcp connection reset

2018-04-13 Thread Juliusz Chroboczek
> i need to reset the tcp connection manually , if one request come from > ipLayer.SrcIP > = 10.2.3.1 then i need to sent the reset connection packet I could be wrong, but I don't think the sockets API makes this possible -- RST segments are normally only sent by the kernel upon receiving a

[go-nuts] Re: [Question]: Are there any plans to teach the compiler to emit VEX encoded instructions ?

2018-03-04 Thread Juliusz Chroboczek
>> I believe using the non-destructive 3 operand form will help a lot in >> reducing the size of binaries. > We would have to make a clear decision as to the oldest amd64 > processor we wanted to support. Right now I believe we support all > amd64 processors. Are we ready to give up on old

[go-nuts] Re: Failed iterator proposals?

2018-10-26 Thread Juliusz Chroboczek
>> for i:=c.Iterator();i.HasNext(); { >> v := i.Next() >> } > I don't like the eyeball friction. Could you please explain what you mean? -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving

[go-nuts] Re: why in source of go compiler, initialize a *gc.Node with the help of a temp struct x? can't we initialize it directly?

2018-12-31 Thread Juliusz Chroboczek
> See https://golang.org/cl/36022. There's a terrifying sort of beauty to it, like a tarantula or a snake. (And it most certainly deserves a comment in the source.) -- Juliusz -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe

[go-nuts] Proposed additions to maphash documentation

2020-02-09 Thread Juliusz Chroboczek
It would be helpful if the introduction to the maphash package immediately stated that it produces 64-bit values, and perhaps restate the fact that the value can be safely reduced using bit masking (already there at the Sum64 method). I'm not sure what is the purpose of the BlockSize method --

[go-nuts] Go-1.14 irreproducibly fails with mlock failure

2020-02-09 Thread Juliusz Chroboczek
The first time I ran go-1.14rc1 on a stock Debian system, I got: runtime: mlock of signal stack failed: 12 runtime: increase the mlock limit (ulimit -l) or runtime: update your kernel to 5.3.15+, 5.4.2+, or 5.5+ fatal error: mlock failed ulimit -l is at 64, which is also the hard

[go-nuts] Re: Why isn't there strings.reverse("str") function?

2020-02-16 Thread Juliusz Chroboczek
> One reason for not implementing it in the standard library is that there > are many possible implementations. Do you want to reverse combining > character sequences for example? Unicode is a complex beast and I suspect > that reversing a string rune-by-rune may easily break important >

[go-nuts] Re: [ generics] Moving forward with the generics design draft

2020-08-23 Thread Juliusz Chroboczek
> We’re going to permit type switches on type parameters that have type > lists, without the “.(type)” syntax. The “(.type)” syntax exists to > clarify code like “switch v := x.(type)”. Could you please give an example of the proposed syntax? -- You received this message because you are

Re: [go-nuts] Re: [ generics] Moving forward with the generics design draft

2020-08-24 Thread Juliusz Chroboczek
>> Could you please give an example of the proposed syntax? > func F[T constraints.Integer]() { > switch T { > case int: > case int8: > } > } Makes perfect sense, thanks. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To

Re: [go-nuts] How do you write "member" with the proposed generics draft?

2020-08-04 Thread Juliusz Chroboczek
Axel Wagner writes: > I feel like https://go2goplay.golang.org/p/RLn9BXjU1OR is a better > compromise than having two functions. > Prolly. Except OP specifically asked about "not that" :) Agreed on both counts. -- You received this message because you are subscribed to the Google

[go-nuts] How do you write "member" with the proposed generics draft?

2020-08-04 Thread Juliusz Chroboczek
I'd be grateful if people could give me an example to help me understand the generics draft. Suppose I've got these two functions: func MemberInt(x int, a []int) bool { for _, v := range a { if v == x { return true } }

[go-nuts] Re: No http.ServeStream() ?

2020-07-04 Thread Juliusz Chroboczek
>> Wondering why there's no http.ServeStream() API to do chunked >> transfer-encoding (or the http2 equivalent), in addition to the nice >> features of ServeContent()... Uh-huh. It would be nice to be able to use the If-None-Match logic for unseekable strings. > Maybe because the current

[go-nuts] Re: How to use atomic_int in cgo?

2021-02-18 Thread Juliusz Chroboczek
> For example, on the Go side write > type chanToUse struct { > c chan int > } > //export MyGoFunction > func MyGoFunction(u unsafe.Pointer, val int) { > cu = (*chanToUse)(u) > cu.c <- val > } Why the struct? Couldn't you just pass a pointer to a chan? -- You received this

[go-nuts] How to version a module that's not providing a stable API?

2021-02-21 Thread Juliusz Chroboczek
Hi, I'm working on an application (a thing with a "main" function) that has a user-visible version. Since the internal modules of the project do not have any backwards compatibility between versions, I've been tagging releases with versions that the Go tools won't recognise (galene-0.3 instead

[go-nuts] Re: Managing perpetually running goroutines

2021-08-30 Thread Juliusz Chroboczek
> I want to be able to terminate each worker independently of others > (i.e. close on worker, wait for it to finish its tasks, but allow > other workers to run if they haven't been signalled to stop). The solution I use is to have each worker take two parameters: - a channel that will be

[go-nuts] Re: Go routine context

2022-10-01 Thread Juliusz Chroboczek
> Very interesting article came out recently. > https://www.infoq.com/articles/java-virtual-threads/ Interesting article, thanks for the pointer. > it has implications for the Go context discussion and the author makes > a very good case as to why using the thread local to hold the > context -

[go-nuts] Re: Which websockets implementation

2022-12-19 Thread Juliusz Chroboczek
> By stdlib, you presumably mean the x/net/websocket package, Careful with this library, it's not quite correct. Websocket is a frame-oriented protocol, while x/net/websocket implements a simplistic API that does not always preserve frame boundaries. Correct implementations include:

[go-nuts] net/netip and UDP servers

2022-12-01 Thread Juliusz Chroboczek
I'm writing a simple UDP server, and I'm trying to use the new net/netip data types. My main loop starts as follows: for { n, a, err := sock.ReadFrom(buf) if err != nil { log.Printf("ReadFrom: %v", err) time.Sleep(100 * time.Millisecond)

[go-nuts] Re: Upgradable RLock

2023-02-05 Thread Juliusz Chroboczek
>> I took some time to put this to a test. The Go program here >> https://go.dev/play/p/378Zn_ZQNaz uses a VERY short holding of the >> lock - but a large % of runtime holding the lock. > Thanks for the benchmark. You're right: if you have hundreds of > goroutines doing nothing but acquiring a

[go-nuts] Re: Windows Go programs not running under Wine anymore.

2023-12-17 Thread Juliusz Chroboczek
> Apparently the change below broke Windows apps when running under Wine as > it made bcryptprimitives.dll a hard requirement now and this dll is not > bundled with Wine. This is true even for programs that do not use it all > (like a simple "hello world" program). > >

[go-nuts] Re: Windows Go programs not running under Wine anymore.

2023-12-17 Thread Juliusz Chroboczek
> Apparently wine 9.0 rc2 includes bcryptprimitives.dll now (I tested on it > and it did work). Thanks for the hint, it apparently works with 8.19 (wine-development in Debian). -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe

[go-nuts] Re: Is json.Marshal deterministic?

2024-04-11 Thread Juliusz Chroboczek
> I don't know if JSON serialization is deterministic, but I know a couple > of cases when it is not. > If the type or some type inside it has a custom JSON marshaller (method > MarshalJSON), then if that function's output is not deterministic, the > whole JSON for the type is not deterministic.

[go-nuts] Is json.Marshal deterministic?

2024-04-09 Thread Juliusz Chroboczek
Hi, Suppose that I call json.Marshal on two structures that are deep equal, or on the same structure at different times. Are the outputs guaranteed to be bytewise identical? (The reason I'm asking is that I'm sending JSON over HTTP, and I need to know whether it is correct to send a strong ETag