Re: [go-nuts] Re: Learning Data Structures and algorithms with Golang
I agree with Ian. My 2 cents. This is a Golang-nuts mailer. Any book on the language may be useful to users to read. - Hemant On Fri, Apr 12, 2019 at 6:59 PM Ian Lance Taylor wrote: > On Fri, Apr 12, 2019 at 3:55 PM wrote: > > > > Bhagvan's disgrceful misuse of this forum to support his commercial > endeavors should result in the exclusion of all his future posts > > Thanks for the note. I encourage you to be respectful, as discussed > at the Gopher Code of Conduct that governs this mailing list > (https://golang.org/conduct). > > Historically we've permitted commercially motivated posts on this > list, such as occasional advertisements of job opportunities. We can > revisit that decision if they start to become a problem. > > Ian > > > > On Friday, April 5, 2019 at 10:28:52 AM UTC-4, Bhagvan Kommadi wrote: > >> > >> Check out my published book on Amazon from packt: > >> > >> Learning Data Structures and algorithms with Golang > >> > >> > https://www.amazon.in/gp/product/1789618509?ref=em_1p_0_ti_=pe_2516461_197852611 > >> > >> > >> #machinelearning #go #fintech #algorithms #datastructures > > > > -- > > 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. > > -- > 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. > -- 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] Re: ctrl-c and Golang
Thanks all for replying. I will look into what solution would work best and get back. Zhipeng, I cannot add a sleep inside the for loop because the loop is sending network packets as fast as possible. Best, Hemant On Monday, February 18, 2019 at 1:41:16 AM UTC-5, Zhipeng Wang wrote: > > I have make a test in version go1.11.4 windows/amd64: > > > func main() { > >const SZ = 65536 >var time_array [SZ]float64 > >c := make(chan os.Signal) >signal.Notify(c, os.Interrupt, syscall.SIGTERM) > >go func() { > <-c > fmt.Printf("You pressed ctrl + C. User interrupted infinite loop.") > fmt.Printf("%v ", time_array); // <=== all zeroes printed. > os.Exit(0) >}() > > >i := 0 >for i < SZ { > time_array[i] = 1 > fmt.Printf("%f bps ", time_array[i]) //<=== value printed is correct. > time.Sleep(time.Second * 1) > i++ >} > } > > > the result is : > > > 1.00 bps 1.00 bps 1.00 bps 1.00 bps 1.00 bps 1.00 bps > 1.00 bps 1.00 bps 1.00 bps You pressed ctrl + C. User interrupted > infinite loop.[1 1 1 1 1 1 > 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...0] > > > so, I think that others wrong in your code. > > > > 在 2019年2月16日星期六 UTC+8下午10:29:45,Hemant Singh写道: >> >> I have the following program. The program is processing network packets >> at 1 Gbps rate. I don't want to print the rate for every packet. Instead, >> I'd like to save the rate in an array and dump the array on Ctrl-c of the >> program. When I dump the array on Ctrl-c, the data is all zeroes. Please >> see "<===" in the program below. Anything else one could do? >> >> Thanks. >> >> -Hemant >> >> func main() { >> >> const SZ = 65536 >> var time_array [SZ]float64 >> >> c := make(chan os.Signal) >> signal.Notify(c, os.Interrupt, syscall.SIGTERM) >> >> go func() { >> <-c >> fmt.Printf("You pressed ctrl + C. User interrupted infinite loop.") >> fmt.Printf("%v ", time_array); <=== all zeroes printed. >> os.Exit(0) >> }() >> >> >> i := 0 >> for { >> ... >> time_array[i] = rate >> fmt.Printf("%f bps ", rate) <=== value printed is correct. >> i++ >> } >> } >> >> -- 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] ctrl-c and Golang
Thanks, David. Let me look into passing as a parameter. Actually, I didn't paste all the code. My array in the for loop does have a check that if array limit is reached, I set the index to zero and overwrite data. Thus, the last 65536 entries are looked at. Hemant On Saturday, February 16, 2019 at 3:16:54 PM UTC-5, David Riley wrote: > > I suspect it's because your reference to the time_array is actually > copying it into your closure that's running as the goroutine instead of > making a reference to it. You might do better to pass that array as a > parameter to the goroutine instead of trying to absorb it as context. > > I should note that your approach of filling a statically sized array is > probably not the best one, because that's going to eventually panic once > you hit the limit. But that's a bit out of scope of this discussion, and > I'm sure you mostly meant it for illustrative purposes. > > > - Dave > > > > On Feb 16, 2019, at 9:29 AM, Hemant Singh > wrote: > > > > I have the following program. The program is processing network packets > at 1 Gbps rate. I don't want to print the rate for every packet. Instead, > I'd like to save the rate in an array and dump the array on Ctrl-c of the > program. When I dump the array on Ctrl-c, the data is all zeroes. Please > see "<===" in the program below. Anything else one could do? > > > > Thanks. > > > > -Hemant > > > > func main() { > > > > const SZ = 65536 > > var time_array [SZ]float64 > > > > c := make(chan os.Signal) > > signal.Notify(c, os.Interrupt, syscall.SIGTERM) > > > > go func() { > > <-c > > fmt.Printf("You pressed ctrl + C. User interrupted infinite loop.") > > fmt.Printf("%v ", time_array); <=== all zeroes printed. > > os.Exit(0) > > }() > > > > > > i := 0 > > for { > > ... > > time_array[i] = rate > > fmt.Printf("%f bps ", rate) <=== value printed is correct. > > i++ > > } > > } > > -- 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] ctrl-c and Golang
I have the following program. The program is processing network packets at 1 Gbps rate. I don't want to print the rate for every packet. Instead, I'd like to save the rate in an array and dump the array on Ctrl-c of the program. When I dump the array on Ctrl-c, the data is all zeroes. Please see "<===" in the program below. Anything else one could do? Thanks. -Hemant func main() { const SZ = 65536 var time_array [SZ]float64 c := make(chan os.Signal) signal.Notify(c, os.Interrupt, syscall.SIGTERM) go func() { <-c fmt.Printf("You pressed ctrl + C. User interrupted infinite loop.") fmt.Printf("%v ", time_array); <=== all zeroes printed. os.Exit(0) }() i := 0 for { ... time_array[i] = rate fmt.Printf("%f bps ", rate) <=== value printed is correct. i++ } } -- 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] inverse of time.Duration?
Thanks all. I figured it out too, but using sprintf and strconv.Atoi. Best. Hemant On Friday, February 15, 2019 at 3:19:38 PM UTC-5, Burak Serdar wrote: > > On Fri, Feb 15, 2019 at 1:15 PM Sam Whited > wrote: > > > > On Fri, Feb 15, 2019, at 20:00, Burak Serdar wrote: > > > rate=1.0/double(dur) > > > > nit: s/double/float64/ > > > oops. Thanks for the correction. > > > > > —Sam > > > > -- > > 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Re: packet filter for VM in golang
In a data center, many operator meter each VM's packet to the Internet for billing In a SR-IOV setup, the NIC would have to meter packets for all VMs being served by the NIC (or smartNIC). A NIC such as the one from Netronome supports BFP in their NIC NPU. There are frontends in C and golang to EBPF that convert to byte code for the NPU on the NIC. If the NIC uses an FPGA, Verilog has to be generated. Hemant On Thursday, October 4, 2018 at 9:26:10 AM UTC-4, Tamás Gulácsi wrote: > > Yes. But where do you place that bpf code? > Where will it run? > What packets will it monitor? > > eBPF is run in a virtual machine _in_the_kernel_. > So a "VM using SR-IOV" bypasses this, also. > > Your monitor must be running in each guest VM, or you must NOT allow > SR-IOV - that bypasses the host's kernel - even the host supervisor! - too! > > 2018. október 4., csütörtök 14:22:49 UTC+2 időpontban Hemant Singh a > következőt írta: > >> Right. However, if a VM is using SR-IOV which connects the VM directly >> to the NIC, the kernel is bypassed. Since sending my email, I also found a >> packet filter in golang: >> >> https://godoc.org/golang.org/x/net/bpf >> >> I have tested the above code yet. >> >> Thanks, >> >> Hemant >> >> On Thursday, October 4, 2018 at 12:22:11 AM UTC-4, Tamás Gulácsi wrote: >>> >>> If your metering runs in the same (virtual) machine as the metered >>> processes, the kernel sees the packets, so ebpf is the fastest. >>> >>> If you run in different machines, or the virtualization skips the host, >>> then you cannot catch the packets. >>> >> -- 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] Re: packet filter for VM in golang
Right. However, if a VM is using SR-IOV which connects the VM directly to the NIC, the kernel is bypassed. Since sending my email, I also found a packet filter in golang: https://godoc.org/golang.org/x/net/bpf I have tested the above code yet. Thanks, Hemant On Thursday, October 4, 2018 at 12:22:11 AM UTC-4, Tamás Gulácsi wrote: > > If your metering runs in the same (virtual) machine as the metered > processes, the kernel sees the packets, so ebpf is the fastest. > > If you run in different machines, or the virtualization skips the host, > then you cannot catch the packets. > -- 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] packet filter for VM in golang
I know about EBPF which is a packet filter in the Linux kernel. However, I think, a virtual machine (VM) using SR-IOV to a NIC bypasses the kernel. Has any packet filter been developed in golang akin to EBPF? Does any Go library have any packet filter or metering functionality? My eventual goal if to meter packets from a VM to the Internet. Thanks, Hemant -- 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] using 'go function_call()' inside Go program
Hi Justin, Got it - thanks much! Hemant On Saturday, September 29, 2018 at 11:58:30 PM UTC-4, Justin Israel wrote: > > > > On Sun, Sep 30, 2018 at 3:47 PM Hemant Singh > wrote: > >> I have a question. I have changed the open goping.go code to return >> error from functions. >> >> The following function is implemented in a .goping.go file. >> >> func ping(config *Config, address, name string, pattern *regexp.Regexp) >> error { } >> >> Another function shown below, in the same .go file, calls 'go ping()'. >> As one can see above, the ping function returns an error. How do I change >> the 'go ping()' code below to grab the error returned from calling ping()? >> I could also use a URL to where a description exists for using 'go >> function_call' inside a Go program. >> >> func ping_main(address string) error { >> go ping(config, address, "DstIP", LATENCY_PATTERN) >> } >> > > In this current form, it is not possible to grab the error because you are > not waiting on the ping() to finish when you call it asynchronously in a > goroutine. If you need the error, the most obvious thing to do is to call > it in a blocking fashion: > > func ping_main(address string) error { > return ping(config, address, "DstIP", LATENCY_PATTERN) > } > > > > But if you need to call it in a non-blocking way, then you have to arrange > a way to receive the error value later once the ping is complete. Wrapping > the existing ping() function might be a way to go: > > func ping_main(address string) <-chan error { > err := make(chan error, 1) > go func() { > err <- ping(config, address, "DstIP", LATENCY_PATTERN) > }() > return err > } > > > > This means the ping still runs in a non-blocking way, but will report the > return value when it is complete. > > >> >> Best, >> >> Hemant >> >> -- >> 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] using 'go function_call()' inside Go program
I have a question. I have changed the open goping.go code to return error from functions. The following function is implemented in a .goping.go file. func ping(config *Config, address, name string, pattern *regexp.Regexp) error { } Another function shown below, in the same .go file, calls 'go ping()'. As one can see above, the ping function returns an error. How do I change the 'go ping()' code below to grab the error returned from calling ping()? I could also use a URL to where a description exists for using 'go function_call' inside a Go program. func ping_main(address string) error { go ping(config, address, "DstIP", LATENCY_PATTERN) } Best, Hemant -- 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] run cmd and capture output on remote machine
I was using ssh with the exec package. However, I didn't know how to capture the output of the cmd run. Today, I studied the exec package and found the Output functionality. Now I can capture the output. https://golang.org/pkg/os/exec/?m=all#Cmd.Output Best, Hemant On Tuesday, September 25, 2018 at 11:29:08 PM UTC-4, Robert Engels wrote: > > You can do this via ssh. > > On Sep 25, 2018, at 7:01 PM, Hemant Singh > wrote: > > I have been able to run a command on a remote machine using Go. Is there > a working example that shows how to capture the output of the command back > to the client machine? Maybe an interactive shell... > > My other choice is to run the command and save its output to a file and > copy the file from the remote machine. > > Thanks, > > Hemant > > -- > 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] run cmd and capture output on remote machine
I have been able to run a command on a remote machine using Go. Is there a working example that shows how to capture the output of the command back to the client machine? Maybe an interactive shell... My other choice is to run the command and save its output to a file and copy the file from the remote machine. Thanks, Hemant -- 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.