Re: [go-nuts] How to determine system requirements for an application?

2020-07-03 Thread thatipelli santhosh
My thought would be write another program or client to send requests to
your k8's deployed app/program to test its limits and determine your
optimal solution.

I think it is kind of doing a stress testing and go has tools for it.

On Sat, Jul 4, 2020, 00:25 smart aquarius  wrote:

> But as per my understanding the threading mechanism of Golang is far more
> better and lightweight than any technology like C# or Java. My use case is
> I wanted to deploy golang api on kuernetes which will be called by 150
> clients every 20 seconds. I don't know how much ram and cpu will be be good
> in such case. Before this, I have never deployed anything on K8. I always
> used azure shared instance for my other technologies where resource
> management is automatic.
>
> On Friday, 3 July 2020 18:04:00 UTC+5:30, Gergely Födémesi wrote:
>>
>> If you can do that in any other language, similar strategy would work in
>> similar go programs as well.
>> (I assume you know you can't do that in the general case. For details see
>> the halting problem.)
>>
>> On Fri, Jul 3, 2020, 11:58  wrote:
>>
>>> Hello,
>>>
>>> If we make an application in golang then how to determine the system
>>> requirements required for its flawless execution.
>>>
>>> What are the parameters to justify the estimated values ​​of CPU and
>>> RAM, especially for the application.exe built in Golang
>>>
>>> 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 golan...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/golang-nuts/15d06b49-a467-4f5c-bd5c-c29c93b576d7o%40googlegroups.com
>>> 
>>> .
>>>
>> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/abd6296e-c9f4-47b8-8871-ab946136f51bo%40googlegroups.com
> 
> .
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAN1Sb7w4F2U4nT6sSmdM_21BE1pRKkNpgiGh_%3DKigQxvO__xVA%40mail.gmail.com.


Re: [go-nuts] ignore json tag for field list in a struct field

2020-07-03 Thread amarjeetanandsingh

On Saturday, July 4, 2020 at 12:25:30 AM UTC+5:30, Lutz Horn wrote:
>
> This code throws an error: 
>
> ./prog.go:10:10: struct field Field2 repeats json tag "field_1" also at 
> prog.go:10 
>
> see https://play.golang.org/p/sFZ-6GWUO0J 
>

ohh 
Yeah, its failing on go 14, but it runs in my local on go 13. 
So probably I shouldn't be worried about dropping the fields from output 
list.
 

> Why not use this: 
>
> type a_1_struct_name struct { 
> Field1 string `json:"field_1"` 
> Field2 string `json:"field_2"` 
> } 
>
> Yeah this would be the proper way to write json tags. But I am writing a 
parser kind of tool that will try to generate the filed tags of struct. So 
I never know how somebody else is going to write their program that I am 
going to parse. 

 
> Von: golan...@googlegroups.com   > im Auftrag von amarjeeta...@gmail.com  <
> amarjeeta...@gmail.com > 
> Gesendet: Freitag, 3. Juli 2020 16:11 
> An: golang-nuts 
> Betreff: [go-nuts] ignore json tag for field list in a struct field 
>
> If there is a json tag with multiple fields in a single line, is there any 
> json parser which will consider the json field name? 
> Like in below, "encoding/json" ignores the fields to unmarshal if there 
> are multiple fields in a single line with a json tag. 
> EX: below code will print nothing. 
>
>
> type a_1_struct_name struct { 
>Field1, Field2 string `json:"field_1"` 
> } 
>
> func main() { 
>a := a_1_struct_name{} 
>j := `{"field_1": "field_1_val"}` 
>if err := json.Unmarshal([]byte(j), ); err != nil { 
>   log.Fatal(err) 
>} 
>fmt.Println(a) 
> } 
>
> But if we remove the json tag `json:"field_1"` and the change the value of 
> json(j) accordingly, it prints {field_1_val } 
>
> I am writing a program to get the json equivalent tag of struct fields 
> using reflect. 
> My question is, is it safe to ignore the fieldList(comma separated struct 
> fields in a single line) if there is a json tag with it? 
>
> -- 
> 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 golan...@googlegroups.com  golang-nuts+unsubscr...@googlegroups.com >. 
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/1932cc53-b7b6-44d2-b855-1639e4c32ac0o%40googlegroups.com
> <
> https://groups.google.com/d/msgid/golang-nuts/1932cc53-b7b6-44d2-b855-1639e4c32ac0o%40googlegroups.com?utm_medium=email_source=footer>.
>  
>
>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/6113cca9-b562-4725-8734-232ace5fff16o%40googlegroups.com.


Re: [go-nuts] Generics: type-list vs method-based constraints -- not orthogonal?

2020-07-03 Thread Steven Blenkinsop
On Fri, Jul 3, 2020 at 3:16 PM, Ian Lance Taylor  wrote:

>
> The trick with this kind of approach is understanding what should
> happen if the type with a package-specified method is converted to an
> empty interface type, handed to some other package, and then in some
> way handed back to the original package.  Does the package-specified
> method survive these conversions?  Why or why not?  Also, how does
> type reflection work: can it discover such methods?  Can it discover
> them in a different package?  There may be answers here but they don't
> jump out as obvious.
>

In order to be consistent, the package-qualified method should survive
conversions the same way as a normal method would. Even unexported methods
do this. Interface satisfaction is a property of the type, not the value.
This would require that packages have the ability to register any extension
methods they define in the runtime representation of an external type
somehow. However, package-qualified methods would never satisfy an
unqualified method constraint in an interface, regardless of any interface
conversions.

Reflection would be able to discover these methods, provided the package
defining them is linked into the binary. Importing a package for its side
effects is already a thing, so that aspect shouldn't be too surprising. You
also don't have the same visibility concerns you have with unexported
methods; there's no particular issue with a package discovering an
extension method defined in a different package at runtime.

One thing that I've found tricky is how to deal with embedding. If these
methods can be promoted, then you have method instances which no single
package owns. The package that defines a struct embedding a type and a
package defining extension methods on the same type don't necessarily know
about each other.

I would think that, in order to have extension methods be promoted, it
would need to be done explicitly. If you could embed a type like pkg(T) which
layered the extension methods defined in package pkg on top of the inherent
methods of type T, then extension methods wouldn't need to be promoted in
the general case. Otherwise, extension methods most likely just wouldn't be
promoted.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CANjmGJt5NHHPU%2BR86GOyRYp1DgEHfZCB5PzbfRQoMTmMtV34mg%40mail.gmail.com.


Re: [go-nuts] [generics] use interfaces in type lists

2020-07-03 Thread Steven Blenkinsop
On Fri, Jul 3, 2020 at 3:05 PM, Ian Lance Taylor  wrote:

>
> Using an interface type in a type list has a defined meaning: the type
> argument must have as its underlying type that interface type.  It
> doesn't mean what I think you want it to mean, which is to serve as a
> union of the type lists of the interface types.  What you suggest
> would not be impossible, but it would mean making an exception to the
> rules for type lists.


One way to disambiguate would be to define a pseudo-type, I(T) for some
interface type I and type T which is identical to T if T implements I, and
is otherwise an empty type that doesn't match any other type. This could
also solve the type switching on type parameters question, since

switch t := t.(type) {
case interface { type int }(T):
   ...
}

would match for a value t of type T if the underlying type of T is int. The
syntax is a bit unwieldy, but it makes it clear that we're matching based
on the type-list semantics and disambiguates between matching to an
interface type vs. matching to a concrete type that implements an
interface. That it looks like a conversion shouldn't be too much of an
issue, since generic functions are also to be followed by either a type
list or a value list.

These pseudo-types would probably only make sense in type lists and type
switches, just as null is only usable as a pseudo-type in type switches.

There might be cleaner ways of doing this, though.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CANjmGJtcJXYsprLD1f6mMJ5ZYW4xaAJgCFhaC5cBM2M4AxvJJg%40mail.gmail.com.


[go-nuts] Re: [generics] Generics pave the way to some kind of polymorphism implementation?

2020-07-03 Thread Aleksandar Milovanović
If someone is interested I simplified the code, commented some more and
added the unmarshall json in the example -
https://go2goplay.golang.org/p/I_ezQ9wyWVx.

Still, I don't know how to type the BuildEmptySpec() in BoxBaseI better
than to return a simple interface{}... If it would
return BoxSpecI(BoxBaseI) it would not be enough.

Aleksandar



On Fri, Jul 3, 2020 at 1:54 PM Aleksandar Milovanović <
aleksan...@videobolt.net> wrote:

> Hi guys,
>
> Thanks for the effort, it is much needed for quite some time. I really
> appreciate the way of introducing the changes, go2go tool and open
> discussion, so I wanted to review them and participate with feedback so you
> can do the best job of understanding the world. With proposed changes, I
> think extending language to support something similar to polymorphism might
> be cheap.
>
> Consider this go playground: https://go2goplay.golang.org/p/jqA4ccWeAKD.
>
> Syntax is awkward currently (some syntax sugar is definitively needed),
> but the point in the test below stands - you do have polymorphic slice, you
> can use base fields and methods, and you can cast to the child structure
> (which contains all the fields and methods from the base). json marshaling
> was added to the example, json unmarshal could be implemented similarly,
> but in that case we need provided mapping from base structure to the
> specialized one, which can't be typed with current generics (for some of
> it, interface{} and reflect would be needed). Could provide that example as
> well, if needed.
>
> Sending this idea as I think it might be interesting, and I think you
> might get some more ideas out of it.
>
> Aleksandar
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAG9NSAWtK%3DeUR9%2B_vCb0X5yun6VF3SB6WOkfq5%2B-cX7KXNQ9vg%40mail.gmail.com.


[go-nuts] Re: gopls performance question

2020-07-03 Thread Luke Mauldin
To add a bit more information to this topic: I also have Vim + ale + gopls 
setup and I tried the same file with Vim + gopls auto complete and it was 
much faster in Vim.  Based on my rough timing, I got the correct auto 
complete responses from gopls in Vim in about 1.5 seconds vs about 4-5 
seconds in VSCode.  I am using VSCode 1.46.1 on Linux.  Could this in some 
way be a VSCode issue instead of gopls?

On Friday, July 3, 2020 at 3:43:53 PM UTC-4, Luke Mauldin wrote:
>
> I have a Go project that is relatively small in terms of number of files 
> (less than 30) but some Go files have auto-generated code that makes them 
> relatively large - some between 3-4 MB.  I counted the SLOC using 
> https://github.com/hhatto/gocloc and it reports about 61K lines of code 
> and 40K lines of comments.  When I am using `gopls` in my project on a 
> pretty high-end workstation (Intel Xeon W-2135, 32 GB RAM, SSD hard drive), 
> it is taking 4-5 seconds to give autocomplete suggestions in VSCode.  Do 
> you have any recommendations of ways to improve the auto complete time?  
> Of note, one of the subdirectories of the project is a package that uses 
> CGO and it is wrapping about 440 C method calls.  If it would help, I can 
> move that subdirectory into its own package entirely and reference it via 
> go.mod?  
>
> Please let me know if you have any suggestions or if I should post this in 
> the `gopls` Github project.
>
> Luke
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/16f60edd-a9b4-499f-8202-53c0edf17903o%40googlegroups.com.


[go-nuts] gopls performance question

2020-07-03 Thread Luke Mauldin
I have a Go project that is relatively small in terms of number of files 
(less than 30) but some Go files have auto-generated code that makes them 
relatively large - some between 3-4 MB.  I counted the SLOC 
using https://github.com/hhatto/gocloc and it reports about 61K lines of 
code and 40K lines of comments.  When I am using `gopls` in my project on a 
pretty high-end workstation (Intel Xeon W-2135, 32 GB RAM, SSD hard drive), 
it is taking 4-5 seconds to give autocomplete suggestions in VSCode.  Do 
you have any recommendations of ways to improve the auto complete time?  
Of note, one of the subdirectories of the project is a package that uses 
CGO and it is wrapping about 440 C method calls.  If it would help, I can 
move that subdirectory into its own package entirely and reference it via 
go.mod?  

Please let me know if you have any suggestions or if I should post this in 
the `gopls` Github project.

Luke

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/e5bc80df-3cdd-4d40-89d7-00af93ee8608o%40googlegroups.com.


Re: [go-nuts] Port to powerpc 440fpu

2020-07-03 Thread Ian Lance Taylor
On Fri, Jul 3, 2020 at 5:54 AM Hugo Cornelis
 wrote:
>
> Thanks for your answer.
>
> On Mon, Jun 29, 2020 at 9:10 PM Ian Lance Taylor  wrote:
>>
>> Thanks for the background.
>>
>> Earlier I suggested looking at the output of "strace -f" for the
>> programs that fail.  Does that show anything of interest?
>
>
> What follows is the analysis of one strace (strace -fv -s 100) attached to 
> the docker daemon.
>
> The strace log file shows the creation of a chain of processes: dockerd forks 
> containerd forks containerd-shim forks runc forks a command that runs inside 
> the container (the command is '/usr/bin/find .').  This is also expected.
>
> When the I/O of the process /usr/bin/find in the docker container is blocked, 
> strace shows that the Golang schedulers are still active:
>
> (line 298015)
> [pid  2266] _newselect(0, NULL, NULL, NULL, {tv_sec=0, tv_usec=1} 
> 
> [pid  2264] sched_yield( 
> [pid  2270] swapcontext(0x2190a580, 0 
> [pid  2264] <... sched_yield resumed>)  = 0
> [pid  2270] <... swapcontext resumed>)  = 0
> [pid  2264] sched_yield( 
> [pid  2270] swapcontext(0, 0x214dda80 
> [pid  2264] <... sched_yield resumed>)  = 0
> [pid  2270] <... swapcontext resumed>)  = 558750336
> [pid  2264] sched_yield( 
> [pid  2270] swapcontext(0, 0x2190a580 
> [pid  2264] <... sched_yield resumed>)  = 0
> [pid  2270] <... swapcontext resumed>)  = 563127680
> [pid  2264] sched_yield( 
> [pid  2270] swapcontext(0x2190a580, 0 
> [pid  2264] <... sched_yield resumed>)  = 0
> [pid  2270] <... swapcontext resumed>)  = 0
> ...
> (line 298134)
> [pid  2266] <... _newselect resumed>)   = 0 (Timeout)
> [pid  2264] <... sched_yield resumed>)  = 0
> [pid  2270] <... swapcontext resumed>)  = 563127680
> [pid  2266] epoll_wait(4,  
> [pid  2264] sched_yield( 
> [pid  2270] swapcontext(0x2190a580, 0 
> [pid  2266] <... epoll_wait resumed>[], 128, 0) = 0
> [pid  2264] <... sched_yield resumed>)  = 0
> [pid  2270] <... swapcontext resumed>)  = 0
> [pid  2266] _newselect(0, NULL, NULL, NULL, {tv_sec=0, tv_usec=1} 
> 
>
> TIDs 2264, 2266 and 2270 belong to the process runc.  The strace log has 
> similar straces for the other processes (dockerd, containerd, 
> containerd-shim), so I assume also their goroutine schedulers were active.  I 
> am actually wondering how to relate the arguments listed in the strace file 
> to the Golang or C code.
>
> Just before the container gets blocked it runs the command 'find .' that 
> should produce output to the terminal (but there is no output at first, that 
> is the problem).  The data is visible in the strace log through the 'write()' 
> system call:
>
> [pid  2204] execve("/usr/bin/find", ["/usr/bin/find", "."], 
> ["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", 
> "HOSTNAME=caae2fb3bccf", "TERM=xterm", "HOME=/root"] 
> ...
> [pid  2204] lstat64(".",  
> ...
> [pid  2204] write(1, ".\n", 2 
> ...
> [pid  2204] lstat64("./var",  
> ...
> [pid  2204] write(1, "./var\n", 6 
> ...
>
> The 'find' process writes 626 lines to stdout (18778 characters, this seems 
> to be reproducible).  The last lines are:
>
> ...
> [pid  2204] lstat64("./sys/kernel/slab/rpc_buffers",  
> ...
> [pid  2204] write(1, "./sys/kernel/slab/rpc_buffers\n", 30 
>
> All the write() system calls except the last one are successfully completed.  
> The last one remains blocked.  At that time PID 2204 hangs for a long time
>
> runc / dockerd / containerd / containerd-shim have continuous activity as in 
> the first strace that I showed above.
>
> When I terminate the docker process with a signal SIGINT, the characters 
> written by PID 2204 are suddenly flushed to the terminal.
>
> Are there anything specific things to look for in the strace files (eg. 
> specific epoll() calls).  Is there a way to map the arguments and return 
> values of swapcontext() to goroutines, or would this be a useless thing to 
> try to do?
>
> This is the analysis of one trial.  Some of the other trials did not start 
> the full chain of processes, it looks like the behaviour of the bug is also 
> timing dependent.


That looks like the process is writing to a pipe that nothing is reading from.

Ian

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcWn-em6UzwUifemOttSToZNyNJ2VoqMZsH%2B-%3DhdUVoC%3DQ%40mail.gmail.com.


Re: [go-nuts] Generics: type-list vs method-based constraints -- not orthogonal?

2020-07-03 Thread Ian Lance Taylor
On Thu, Jul 2, 2020 at 9:48 PM Steven Blenkinsop  wrote:
>
> Another option for abstracting over builtin and custom type cases would be to 
> add namespaced extension methods. Basically, a package could add methods to a 
> builtin type which are namespaced by the package, and then interfaces could 
> qualify their method names with the particular package whose methods they 
> want to use. Downstream packages would be able to satisfy these methods only 
> for the types they define, like with normal "free" methods. This change would 
> potentially have a far reaching impact, but it would sidestep needing to add 
> a lot of names to the language.
>
> type CustomOrdered(type T) interface {
> package.Less(other T) bool
> }
>
> func (x int) package.Less(y int) bool {
> return x < y
> }
>
> It would be nice if you could do this for all types that implement 
> constraints.Ordered in one definition, but that's a whole other can of worms.

The trick with this kind of approach is understanding what should
happen if the type with a package-specified method is converted to an
empty interface type, handed to some other package, and then in some
way handed back to the original package.  Does the package-specified
method survive these conversions?  Why or why not?  Also, how does
type reflection work: can it discover such methods?  Can it discover
them in a different package?  There may be answers here but they don't
jump out as obvious.

Ian

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcXr5%2BSczr7cx6gwY0tOiErXerG9p2Nk__kB8GwShdrpXg%40mail.gmail.com.


Re: [go-nuts] Generics: type-list vs method-based constraints -- not orthogonal?

2020-07-03 Thread Ian Lance Taylor
On Thu, Jul 2, 2020 at 9:02 PM Ben Hoyt  wrote:
>
> Thanks. You're right about the Map with the comparison function being
> more flexible. That helps allay my concerns for ordered data
> structures.
>
> I guess what I'm worried about is for someone writing a "slices"
> library and wants to include a function like slices.Smallest(). Do
> they give it an Ordered type-list constraint or an constraint with a
> Less method? How will they know which of the following to do?
>
> 1) Only include Smallest() and hope nobody who uses big.Int comes along.
> 2) Include two versions, Smallest(type T Ordered)(s []T) for int and
> float64 etc, and SmallestCmp(type T)(s []T, func (x, y T) int) so
> people can use SmallestCmp(bigs, big.Int.Cmp)?
> 3) Something else, like Smallest() plus a SmallestCustom() that uses
> CustomOrdered
>
> Can you flesh out what you're thinking of w.r.t Smallest() and taking
> "an approach like the sort example"?

I was thinking of a comparison function, with a wrapper that uses a
little comparison function that calls Less.  It's more work on the
package writer side, but it seems pretty straightforward on the part
of the caller of the function.

I think we are always going to face this dichotomy unless we introduce
a large set of standard methods for builtin types, or add some way for
people to define operator methods for their own types.  Both seem like
big changes to the language, and while they would be convenient for
certain uses of generics it's not clear to me that they are essential.
That is, I think generics can be useful even without those features,
and I don't think generics precludes adding those features later if
they seem useful.

Ian


> On Fri, Jul 3, 2020 at 3:37 PM Ian Lance Taylor  wrote:
> >
> > On Thu, Jul 2, 2020 at 4:59 PM ben...@gmail.com  wrote:
> > >
> > > This thread on lobste.rs made me wonder if the difference between 
> > > type-list constraints and method-interface constraints is going to cause 
> > > a bunch of issues or code duplication. There's a lack of orthogonality 
> > > here that makes me uneasy.
> > >
> > > For example, the Smallest() function in this proposal takes a slice of 
> > > []T, where T is "type T constraints.Ordered", a type-list based 
> > > constraint. That means Smallest() will only work with the built-in types 
> > > specified in the type list (or types with one of those as an underlying 
> > > type), and can't be used with more complex struct types.
> > >
> > > For it to work for other types, you'd have to write a second version of 
> > > Smallest() -- code duplication -- that took a method-interface based 
> > > constraint like so:
> > >
> > > type CustomOrdered(type T) interface {
> > > Less(other T) bool
> > > }
> > >
> > > Arguably Smallest() would still be quite useful even if it only works for 
> > > builtin integer and float point types, but with the type-list Ordered it 
> > > wouldn't work for (say) big.Int, a custom Decimal type, or a more complex 
> > > struct type.
> > >
> > > But I think this is worse for ordering-based *data structures* like Tree 
> > > of T. If done with the type-list Ordered, the tree could only store 
> > > built-in types, which isn't that useful. Using a constraint like 
> > > CustomOrdered would work and be more flexible ... but then a basic 
> > > Tree(int) wouldn't work. You'd have to do Tree(MyInt) and convert 
> > > everything from int to MyInt on the way in, and MyInt back to int on the 
> > > way out -- a bunch of type conversion boilerplate.
> > >
> > > Or you'd end up writing two versions of your generic Tree: BuiltinTree 
> > > that uses Ordered (type lists), and CustomTree that uses CustomOrdered 
> > > (interface with Less). Not very nice.
> > >
> > > (Here's some Go2Go code which shows this for Smallest: 
> > > https://go2goplay.golang.org/p/Rbs374BqPWw)
> > >
> > > I'm not sure how the proposal solves this for something like Smallest() 
> > > ... I don't think it does. For ordered data structures, like the Map 
> > > example, it passes in a custom "compare" function to the initializer and 
> > > kind of side-steps the issue. Which isn't bad for data structures as it'd 
> > > still eliminate a lot of code, but it would be kind of a pain for little 
> > > algorithms like Smallest().
> > >
> > > Thoughts?
> >
> > What you say is true.  I don't know of a way around the basic problem
> > other than introducing methods on basic types.  That would be a big
> > change to the language, and would require introducing a large number
> > of new names.
> >
> > The way I would suggest handling your Tree example is by making the
> > basic data structure take a comparison function.  Then you can write
> > tiny wrappers that create the function for any ordered type, or for
> > any type with a Less method.  Or people can just pass their own
> > comparison function.  You suggest that the Map example sidesteps the
> > issue by using a comparison function, which is true, but the Map data
> > structure is also more 

Re: [go-nuts] [generics] use interfaces in type lists

2020-07-03 Thread Ian Lance Taylor
On Fri, Jul 3, 2020 at 9:46 AM Davor Kapša  wrote:
>
> Is it planned to combine type list with embed interfaces,
> or it is too confusing ?
>
> type numeric interface {
> type integers, floats
> }
>
> type integers interface {
> type int, int8, int16, int32, int64, unsigneds
> }
>
> type unsigneds interface {
> type uint, uint8, uint16, uint32, uint64
> }
>
> type floats interface {
> type float32, float64
> }
>
> https://go2goplay.golang.org/p/6X5WZxWIcHE
>
> Thanks for current draft, it feels very idiomatic to me.

Using an interface type in a type list has a defined meaning: the type
argument must have as its underlying type that interface type.  It
doesn't mean what I think you want it to mean, which is to serve as a
union of the type lists of the interface types.  What you suggest
would not be impossible, but it would mean making an exception to the
rules for type lists.

Ian

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcWu6GBjKWLz9PA5di5L1mC4p8tQuSfXJB_ME%2B0kcH1ykg%40mail.gmail.com.


[go-nuts] [generics] Generics pave the way to some kind of polymorphism implementation?

2020-07-03 Thread Aleksandar Milovanović
Hi guys,

Thanks for the effort, it is much needed for quite some time. I really
appreciate the way of introducing the changes, go2go tool and open
discussion, so I wanted to review them and participate with feedback so you
can do the best job of understanding the world. With proposed changes, I
think extending language to support something similar to polymorphism might
be cheap.

Consider this go playground: https://go2goplay.golang.org/p/jqA4ccWeAKD.

Syntax is awkward currently (some syntax sugar is definitively needed), but
the point in the test below stands - you do have polymorphic slice, you can
use base fields and methods, and you can cast to the child structure (which
contains all the fields and methods from the base). json marshaling was
added to the example, json unmarshal could be implemented similarly, but in
that case we need provided mapping from base structure to the specialized
one, which can't be typed with current generics (for some of it,
interface{} and reflect would be needed). Could provide that example as
well, if needed.

Sending this idea as I think it might be interesting, and I think you might
get some more ideas out of it.

Aleksandar

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAG9NSAVMKL7FtkZURP0j4utts2Kya0RUvg2_qHCdxTE_JMii9g%40mail.gmail.com.


Re: [go-nuts] How to determine system requirements for an application?

2020-07-03 Thread smart aquarius
But as per my understanding the threading mechanism of Golang is far more 
better and lightweight than any technology like C# or Java. My use case is 
I wanted to deploy golang api on kuernetes which will be called by 150 
clients every 20 seconds. I don't know how much ram and cpu will be be good 
in such case. Before this, I have never deployed anything on K8. I always 
used azure shared instance for my other technologies where resource 
management is automatic.  

On Friday, 3 July 2020 18:04:00 UTC+5:30, Gergely Födémesi wrote:
>
> If you can do that in any other language, similar strategy would work in 
> similar go programs as well.
> (I assume you know you can't do that in the general case. For details see 
> the halting problem.)
>
> On Fri, Jul 3, 2020, 11:58 > wrote:
>
>> Hello,
>>
>> If we make an application in golang then how to determine the system 
>> requirements required for its flawless execution. 
>>
>> What are the parameters to justify the estimated values ​​of CPU and RAM, 
>> especially for the application.exe built in Golang
>>
>> 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 golan...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/15d06b49-a467-4f5c-bd5c-c29c93b576d7o%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/abd6296e-c9f4-47b8-8871-ab946136f51bo%40googlegroups.com.


AW: [go-nuts] ignore json tag for field list in a struct field

2020-07-03 Thread Lutz Horn
This code throws an error:

./prog.go:10:10: struct field Field2 repeats json tag "field_1" also at 
prog.go:10

see https://play.golang.org/p/sFZ-6GWUO0J

Why not use this:

type a_1_struct_name struct {
Field1 string `json:"field_1"`
Field2 string `json:"field_2"`
}


Von: golang-nuts@googlegroups.com  im Auftrag von 
amarjeetanandsi...@gmail.com 
Gesendet: Freitag, 3. Juli 2020 16:11
An: golang-nuts
Betreff: [go-nuts] ignore json tag for field list in a struct field

If there is a json tag with multiple fields in a single line, is there any json 
parser which will consider the json field name?
Like in below, "encoding/json" ignores the fields to unmarshal if there are 
multiple fields in a single line with a json tag.
EX: below code will print nothing.


type a_1_struct_name struct {
   Field1, Field2 string `json:"field_1"`
}

func main() {
   a := a_1_struct_name{}
   j := `{"field_1": "field_1_val"}`
   if err := json.Unmarshal([]byte(j), ); err != nil {
  log.Fatal(err)
   }
   fmt.Println(a)
}

But if we remove the json tag `json:"field_1"` and the change the value of 
json(j) accordingly, it prints {field_1_val }

I am writing a program to get the json equivalent tag of struct fields using 
reflect.
My question is, is it safe to ignore the fieldList(comma separated struct 
fields in a single line) if there is a json tag with it?

--
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/1932cc53-b7b6-44d2-b855-1639e4c32ac0o%40googlegroups.com.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/AM7P191MB1060D7B923A795E0455FE6B89E6A0%40AM7P191MB1060.EURP191.PROD.OUTLOOK.COM.


[go-nuts] [generics] use interfaces in type lists

2020-07-03 Thread Davor Kapša
Hi, 

Is it planned to combine type list with embed interfaces,
or it is too confusing ?

type numeric interface {
type integers, floats
}

type integers interface {
type int, int8, int16, int32, int64, unsigneds
}

type unsigneds interface {
type uint, uint8, uint16, uint32, uint64
}

type floats interface {
type float32, float64
}

https://go2goplay.golang.org/p/6X5WZxWIcHE 


Thanks for current draft, it feels very idiomatic to me.

--- Davor

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/0e7a854f-ed75-4d06-8fed-73306f9d3ef7o%40googlegroups.com.


Re: [go-nuts] Worker Pool vs. New Goroutine For Each Task

2020-07-03 Thread Andrei Tudor Călin
Check out Bryan's talk[0], in particular from ~27:00 onward, where worker
pools are discussed. I highly recommend the entire talk.

[0] https://www.youtube.com/watch?v=5zXAHh5tJqQ

On Fri, Jul 3, 2020 at 5:03 PM Atakan Çolak 
wrote:

> Hiya everyone,
>
> I have a simple processor function that takes in data, processes it, and
> sends it to a fellow goroutine which will eventually write them to DB. My
> main concern is just to maximise current task/sec with a hard limit on CPU
> usage. Currently I'm using a worker pool model that share a task channel to
> receive their tasks. I think another alternative solution could be setting
> GOMAXPROCS and generate a new goroutine for each task, as Go is able to
> handle thousands of goroutines easily. I wanted to ask about ups and down
> of both of these approaches.
>
> Thank you.
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/567ff4bd-a99e-4af5-bd46-7859d98575cbo%40googlegroups.com
> 
> .
>


-- 
Andrei Călin

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CANnvmN5zQjYLMjLEhi_oUDJzegCdiPUfuR5ET00zB7BN9dA_4w%40mail.gmail.com.


Re: [go-nuts] Worker Pool vs. New Goroutine For Each Task

2020-07-03 Thread Michael Jones
If you change then will anything limit the peak degree of parallelism?

The worker pool size is such a limiting factor. May be important for you.
If so, plan another throttling mechanism.

On Fri, Jul 3, 2020 at 7:03 AM Atakan Çolak 
wrote:

> Hiya everyone,
>
> I have a simple processor function that takes in data, processes it, and
> sends it to a fellow goroutine which will eventually write them to DB. My
> main concern is just to maximise current task/sec with a hard limit on CPU
> usage. Currently I'm using a worker pool model that share a task channel to
> receive their tasks. I think another alternative solution could be setting
> GOMAXPROCS and generate a new goroutine for each task, as Go is able to
> handle thousands of goroutines easily. I wanted to ask about ups and down
> of both of these approaches.
>
> Thank you.
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/567ff4bd-a99e-4af5-bd46-7859d98575cbo%40googlegroups.com
> 
> .
>


-- 

*Michael T. jonesmichael.jo...@gmail.com *

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CALoEmQx4Wf5Czs8LmR2caOTYT5vVNZpzWNn0Yj6aUhhR9RHmFw%40mail.gmail.com.


[go-nuts] ignore json tag for field list in a struct field

2020-07-03 Thread amarjeetanandsingh
If there is a json tag with multiple fields in a single line, is there any 
json parser which will consider the json field name?
Like in below, "encoding/json" ignores the fields to unmarshal if there are 
multiple fields in a single line with a json tag.
EX: below code will print nothing.

type a_1_struct_name struct {
   Field1, Field2 string `json:"field_1"`
}

func main() {
   a := a_1_struct_name{}
   j := `{"field_1": "field_1_val"}`
   if err := json.Unmarshal([]byte(j), ); err != nil {
  log.Fatal(err)
   }
   fmt.Println(a)
}


But if we remove the json tag `json:"field_1"` and the change the value of 
json(*j*) accordingly, it prints {field_1_val }

I am writing a program to get the json equivalent tag of struct fields 
using reflect. 
*My question is,* is it safe to ignore the fieldList(*comma separated 
struct fields in a single line*) if there is a json tag with it?

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/1932cc53-b7b6-44d2-b855-1639e4c32ac0o%40googlegroups.com.


[go-nuts] Worker Pool vs. New Goroutine For Each Task

2020-07-03 Thread Atakan Çolak
Hiya everyone, 

I have a simple processor function that takes in data, processes it, and 
sends it to a fellow goroutine which will eventually write them to DB. My 
main concern is just to maximise current task/sec with a hard limit on CPU 
usage. Currently I'm using a worker pool model that share a task channel to 
receive their tasks. I think another alternative solution could be setting 
GOMAXPROCS and generate a new goroutine for each task, as Go is able to 
handle thousands of goroutines easily. I wanted to ask about ups and down 
of both of these approaches.

Thank you.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/567ff4bd-a99e-4af5-bd46-7859d98575cbo%40googlegroups.com.


Re: [go-nuts] Port to powerpc 440fpu

2020-07-03 Thread Hugo Cornelis
Thanks for your answer.

On Mon, Jun 29, 2020 at 9:10 PM Ian Lance Taylor  wrote:

> Thanks for the background.
>
> Earlier I suggested looking at the output of "strace -f" for the
> programs that fail.  Does that show anything of interest?
>

What follows is the analysis of one strace (strace -fv -s 100) attached to
the docker daemon.

The strace log file shows the creation of a chain of processes: dockerd
forks containerd forks containerd-shim forks runc forks a command that runs
inside the container (the command is '/usr/bin/find .').  This is also
expected.

When the I/O of the process /usr/bin/find in the docker container is
blocked, strace shows that the Golang schedulers are still active:

(line 298015)
[pid  2266] _newselect(0, NULL, NULL, NULL, {tv_sec=0, tv_usec=1}

[pid  2264] sched_yield( 
[pid  2270] swapcontext(0x2190a580, 0 
[pid  2264] <... sched_yield resumed>)  = 0
[pid  2270] <... swapcontext resumed>)  = 0
[pid  2264] sched_yield( 
[pid  2270] swapcontext(0, 0x214dda80 
[pid  2264] <... sched_yield resumed>)  = 0
[pid  2270] <... swapcontext resumed>)  = 558750336
[pid  2264] sched_yield( 
[pid  2270] swapcontext(0, 0x2190a580 
[pid  2264] <... sched_yield resumed>)  = 0
[pid  2270] <... swapcontext resumed>)  = 563127680
[pid  2264] sched_yield( 
[pid  2270] swapcontext(0x2190a580, 0 
[pid  2264] <... sched_yield resumed>)  = 0
[pid  2270] <... swapcontext resumed>)  = 0
...
(line 298134)
[pid  2266] <... _newselect resumed>)   = 0 (Timeout)
[pid  2264] <... sched_yield resumed>)  = 0
[pid  2270] <... swapcontext resumed>)  = 563127680
[pid  2266] epoll_wait(4,  
[pid  2264] sched_yield( 
[pid  2270] swapcontext(0x2190a580, 0 
[pid  2266] <... epoll_wait resumed>[], 128, 0) = 0
[pid  2264] <... sched_yield resumed>)  = 0
[pid  2270] <... swapcontext resumed>)  = 0
[pid  2266] _newselect(0, NULL, NULL, NULL, {tv_sec=0, tv_usec=1}


TIDs 2264, 2266 and 2270 belong to the process runc.  The strace log has
similar straces for the other processes (dockerd, containerd,
containerd-shim), so I assume also their goroutine schedulers were active.
I am actually wondering how to relate the arguments listed in the strace
file to the Golang or C code.

Just before the container gets blocked it runs the command 'find .' that
should produce output to the terminal (but there is no output at first,
that is the problem).  The data is visible in the strace log through the
'write()' system call:

[pid  2204] execve("/usr/bin/find", ["/usr/bin/find", "."],
["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"HOSTNAME=caae2fb3bccf", "TERM=xterm", "HOME=/root"] 
...
[pid  2204] lstat64(".",  
...
[pid  2204] write(1, ".\n", 2 
...
[pid  2204] lstat64("./var",  
...
[pid  2204] write(1, "./var\n", 6 
...

The 'find' process writes 626 lines to stdout (18778 characters, this seems
to be reproducible).  The last lines are:

...
[pid  2204] lstat64("./sys/kernel/slab/rpc_buffers",  
...
[pid  2204] write(1, "./sys/kernel/slab/rpc_buffers\n", 30 

All the write() system calls except the last one are successfully
completed.  The last one remains blocked.  At that time PID 2204 hangs for
a long time

runc / dockerd / containerd / containerd-shim have continuous activity as
in the first strace that I showed above.

When I terminate the docker process with a signal SIGINT, the characters
written by PID 2204 are suddenly flushed to the terminal.

Are there anything specific things to look for in the strace files (eg.
specific epoll() calls).  Is there a way to map the arguments and return
values of swapcontext() to goroutines, or would this be a useless thing to
try to do?

This is the analysis of one trial.  Some of the other trials did not start
the full chain of processes, it looks like the behaviour of the bug is also
timing dependent.

Hugo



>
> Ian
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAARrXCTpc%2BFzT9xZn%3DD_beLaupnes6fLfdM2OGXj5kJM5c__zg%40mail.gmail.com.


Re: [go-nuts] How to determine system requirements for an application?

2020-07-03 Thread fgergo
If you can do that in any other language, similar strategy would work in
similar go programs as well.
(I assume you know you can't do that in the general case. For details see
the halting problem.)

On Fri, Jul 3, 2020, 11:58  wrote:

> Hello,
>
> If we make an application in golang then how to determine the system
> requirements required for its flawless execution.
>
> What are the parameters to justify the estimated values ​​of CPU and RAM,
> especially for the application.exe built in Golang
>
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/15d06b49-a467-4f5c-bd5c-c29c93b576d7o%40googlegroups.com
> 
> .
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CA%2Bctqrp%2B0J84-vM-7%3DRDEFZKYtQ7A7fV6haX%3DbPB1zA0xOrZFw%40mail.gmail.com.


[go-nuts] How to determine system requirements for an application?

2020-07-03 Thread smartaquarius10
Hello,

If we make an application in golang then how to determine the system 
requirements required for its flawless execution. 

What are the parameters to justify the estimated values ​​of CPU and RAM, 
especially for the application.exe built in Golang

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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/15d06b49-a467-4f5c-bd5c-c29c93b576d7o%40googlegroups.com.


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

2020-07-03 Thread Tamás Gulácsi
2020. július 2., csütörtök 20:09:05 UTC+2 időpontban Liam a következőt írta:
>
> 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()...
>
> Has it been considered? Does it merit a proposal?
>
> If not, some example code in the docs would be helpful...
>
>
Maybe because the current ServeHTTP does the chunked transfer-encoding when 
Content-Length is not set, and the Writes are more than the predefined 
buffer length?

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/93abd35b-ca9d-48f2-8346-687eea081605o%40googlegroups.com.