[go-nuts] Re: Is there a way omit the the additional allocation when passing []byte to C function?

2017-11-30 Thread Владислав Митов
Thanks a lot. Yeah, that works but that's not actually my code so I'll have to check with the guys that own it if it is feasible to change the C code, otherwise I'll do the wrapper. On Thursday, November 30, 2017 at 1:35:44 AM UTC+2, xingtao zhao wrote: > > /* C code: > > struct PKCS15_Ret { >

[go-nuts] Building a select friendly condition type

2017-11-30 Thread Artyom Pervukhin
Hi, Some time ago I had a similar use-case and came up with the following pattern: https://play.golang.org/p/zQglq3ObvH — it's based on guarantee that receive operation on a closed channel always proceeds immediately. -- You received this message because you are subscribed to the Google Groups

[go-nuts] Re: Building a select friendly condition type

2017-11-30 Thread Dan Mullineux
The for loop in the main goroutine will lose individual notifications between each Register in that loop but it looks guaranteed that each Register will know if at least one Notification happened after it last knew about a Notification. So if that was, and it sounds like it was, the intention,

[go-nuts] Re: Building a select friendly condition type

2017-11-30 Thread Dave Cheney
That is correct. I should have made this clearer; the intent is to fire a notification when the cache has changed since the last time it was sent to the client, knowing how many times it has changed (for example while it's being transmitted a whole bunch of changes may have been applied) is not

[go-nuts] Re: Building a select friendly condition type

2017-11-30 Thread Dave Cheney
thanks for sharing your implementation. I have a few questions. 1. is NewCond needed? Is this sufficient? var c Cond c.Notify() 2. In notify, is the two arg form of the .(*barr) conversion necessary? If the value is not initialised then the assertion to *barr will fail. If it is initiased then

Re: [go-nuts] Re: Building a select friendly condition type

2017-11-30 Thread Artyom Pervukhin
Dave, you’re absolutely right about the possibility of losing channel on lines 43-47, in my use case that was not an issue because of serialized Notify calls. On a second look I see a way to simplify my code essentially to this: https://play.golang.org/p/F8g-ltlXao

[go-nuts] Re: Building a select friendly condition type

2017-11-30 Thread Dan Mullineux
Yes then as it looks correct I am sure I couldn't do any better (fwiw). If you are happy that volumes of waiters vs notifications wouldn't behave as a `leak` then `c.waiters = c.waiters[:0]` is a fair tradeoff vs GC On Thursday, 30 November 2017 12:26:21 UTC, Dave Cheney wrote: > > That is corr

[go-nuts] Re: profiling webserver with pprof and router middleware

2017-11-30 Thread Karan Chaudhary
Are you just trying to see how heap allocation can be seen using debug/pprof? Maybe you're allocating too less. Try to allocate exponentialy. package main import ( "log" "net/http" "time" _ "net/http/pprof" ) func expalloc() { x := make([]int, 0) for i := 0; i < 10; i++ { x = append(x, i)

[go-nuts] Re: profiling webserver with pprof and router middleware

2017-11-30 Thread Karan Chaudhary
Attaching png: On Thursday, 30 November 2017 19:09:04 UTC+5:30, Karan Chaudhary wrote: > > Are you just trying to see how heap allocation can be seen using > de

[go-nuts] Re: How to check if db connection active after database server restarts ?

2017-11-30 Thread Karan Chaudhary
If at any point it is to be checked that connection is active or not, `Ping` can be used as stated by Shawn. And any operation on dirty conn should fail, as the session is corrupt. Though, it seems, auto-reconnection is already done by database/sql. https://github.com/golang/go/issues/5718 O

[go-nuts] Re: Sort a huge slice of data around 2GB

2017-11-30 Thread Slawomir Pryczek
It should be very simple if you have additional 2G of memory. You divide the data to X parts where X is power of 2 and X needs to be less than number of cores available. Eg. for 2000MB it can be 250x8. Then you sort it in paralell using built-in sorting function and at the end you just concaten

[go-nuts] Re: Sort a huge slice of data around 2GB

2017-11-30 Thread Subramanian K
Thanks all, did some metrics on comparison function "Less", had JSON data in this huge file, had to unmarshall JSON data and then do a comparison based on obtained data. unmarshalling took 98% of time in this comparison. Looking to avoid unmarshaliing and finding an alternative way to do this. T

[go-nuts] Re: net/http Server Shutdown does not free up the port upon return

2017-11-30 Thread Karan Chaudhary
I think, this is what is happening. I don't think this is a bug. When server shuts down, it asks the kernel to release the resources it was holding. One of the resources is port. Though the program closed the port (by the shutdown()), but kernel still keeps it in TIME_WAIT state. Now if w

Re: [go-nuts] Re: Sort a huge slice of data around 2GB

2017-11-30 Thread Michael Jones
The general way this is done is to extract the keys needed for the sorting along, sort this index, and then either use the index as an access mechanism to access the unmodified bulk data, or, to do a single pass reordering. On Thu, Nov 30, 2017 at 8:36 AM, Subramanian K wrote: > Thanks all, did

[go-nuts] Re: Building a select friendly condition type

2017-11-30 Thread Steven Harris
On Thursday, November 30, 2017 at 12:32:10 AM UTC-5, Dave Cheney wrote: > > But I'm wondering if others have found themselves in the same position, > and if so, what were your solutions? > I'm not sure if this approach satisfies all of your requirements, but if you want those registering to be n

Re: [go-nuts] Building a select friendly condition type

2017-11-30 Thread Ian Lance Taylor
On Wed, Nov 29, 2017 at 9:32 PM, Dave Cheney wrote: > > Anyone for a round of code golf? > > I'm working on a piece of code for a streaming gRPC server and have found > myself in the position that I need to wait for a notification event (in this > case that a cache has been updated and I need to s

[go-nuts] net/http 404 error handling

2017-11-30 Thread Nathan Fisher
Hi All, I came across this issue on GitHub relating to 404 handling in which Brad F. said net/http will not implement templating. https://github.com/golang/go/issues/10707 Perhaps a silly question but why not change http.NotFound into a function pointer like this: ``` var NotFound = func(w Resp

[go-nuts] Re: net/http 404 error handling

2017-11-30 Thread anmol via golang-nuts
Not disagreeing or agreeing but just want to mention that Brad's suggested solution is not ideal because the a http.ResponseWriter may implement more interfaces than just http.ResponseWriter. When you wrap a response writer with an intercepting response writer, you cannot cast the intercepting r

Re: [go-nuts] Re: Reading os.Stdin, Unbuffered

2017-11-30 Thread Robert Solomon
Thanks On Nov 28, 2017 8:03 PM, "Robert Solomon" wrote: I trying to learn how to use pseudo-terminal-go. It works fine under Ubuntu 16.04 amd64. But not fine on win10 64 bit. go get github.com/carmark/pseudo-terminal-go/terminal #github.com/carmark/pseudo-terminal-go/terminal github.com\carm