Re: [go-nuts] Problem with HINDI NAMES

2017-05-26 Thread Bakul Shah
On May 25, 2017, at 6:25 PM, Vikram Rawat  wrote:
> 
> Hello Bakul,
> 
> I am just an R programmer(by which i mean i don't understand programming 
> much). I was looking for an alternative way to python. I really don't 
> understand what you said but i want to let you all know one thing.
> 
> English hasonly 26 characters but those are not sufficient for languages like 
> hindi, bengali, gurumukhi, malyalam and many other phonetic languages. So we 
> use entire keyboard to type letters.
> 
> In the above example सोम is a proper word with a meaning we just simply can't 
> ignore ो or letters like that at all.

See the current Go language rules for identifiers in the language reference, 
which do not allow vowel signs as part of an identifier (they do not belong to 
unicode category "Letter").  As Rob pointed out, 
https://github.com/golang/go/issues/5167 
 covers this issue. To allow vowel 
signs in an identifier, the language definition has to change.

As per the discussion on that page it appears this issue won't be resolved in 
Go1. This is probably because very few people care about this issue so it gets 
a low priority. Most Indian programmers seem fine using English identifiers in 
any case. I would like to see this fixed because I consider it a language bug.

I suggested a solution which is simple to implement. At present no such Indic 
identifier exists so not everything in the ecosystem needs to be fixed right 
away! One can start with the compiler. Other tools can be fixed later as per 
need.

But realistically this is a low priority item -- don't hold your breath! And 
don't wait for Go2 either!

> Please tell me what to do. I really want to write program in my language 
> because there arenone written yet.

This is a separate issue and should be discussed outside of this group but some 
remarks:

Just choosing identifiers in your language does not mean you are "writing 
programs in your language".  You will also be using standard libraries which 
have english names for exported functions, variables and types etc. My advice 
is to stick to English. Until there is a complete ecosystem in Hindi or 
whatever local language (meaning libraries, documentation etc. etc.) the user 
has to know English in any case and using Hindi names means you will have fewer 
people who can help you!

If you really want to work with Hindi, my advice is to work on Hindi language 
related tools. In general s/w support for most Indian languages is lagging far 
far behind English (and I suspect other European languages + Chinese, Japanese 
& Korean). But this is best discussed offline and not on this list.

-- 
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: idea: generic methods on slices with some generic type support []string.Map(string) []string => [].Map() []

2017-05-26 Thread mhhcbon
would not it be nice to write []string{"hello}.Map(strings.ToUpper) ? 

And so for userland types the language accept, 
[]*MyType.Filter(func(*MyType)*MyType).Map(...).First()//etc.

IRL, because the total lack of such struct in the language might let you 
think the idea is superfluous with the currrent 
language/idioms/whateveryounameit, 
I have this example i like,

// GetByID read the Tomate of given IDfunc (t Controller) GetByID(getID string) 
(jsonResBody *Tomate, err error) {
t.backend.Transact(func(backend *Tomates) {
jsonResBody = backend.
Filter(FilterTomates.ByID(getID)).
First()
})
if jsonResBody == nil {
err = &NotFoundError{errors.New("Tomate not found")}
}
return jsonResBody, err
}


The code is not cluttered with extra if/else/for statements that i d have 
to introduce using regular constructs proposed by the language.


What are the example that needs extended generic support that interface can 
fulfilled ?
This one ?

type B string

func A([]string){}

func main(){ 
 var x []B
 A(x)
} 

? 
What else chan  ?
https://gist.github.com/mchirico/df9fad3e7a5ea0c4527a ?
map ?




in all cases, it ends up with a manual conversion should occur, can t the 
language handle it ?
Do the compatibility check needed to slice conversion and produce the 
results or err appropriately.
Even better, take advantage of it to implement compilation rules ?

sX, err := conv([]string, x) or panic(err)
A(sX)

outChan, err := conv(<- chan /whatever compatible/, inputChan) or panic(err)

Are there more examples in sight ?




On Wednesday, May 24, 2017 at 9:52:27 AM UTC+2, mhh...@gmail.com wrote:
>
> see the title, only for what s needed 
> Slice/Splice/Each/Map/First/Last/Reverse/Sort ect ect not len, for reason. 
> so interface system serves the userland by its definition of struct, and 
> the basic slice type provided by the language is fully operational, without 
> breaking, btw. i don t go further in evaluation, i leave that to the 
> reader, just trying to work decently.
>

-- 
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: idea: generic methods on slices with some generic type support []string.Map(string) []string => [].Map() []

2017-05-26 Thread mhhcbon
as i m on it,

please consider, what below code might be with little imagination,


// Create a new Tomate
func (t Controller) Create(postColor *string) (jsonResBody *Tomate, err error) {
 
   mustNot(postColor, nil) or 
 return ... &UserInputError{errors.New("Missing color parameter")}
 
   color, _ := mustNot(strings.TrimSpace(*postColor), "") or 
 return ... &UserInputError{errors.New("color must not be empty")}

   t.backend.Transact(func(backend *Tomates) {
 
 must(backend.Filter(FilterTomates.ByColor(color)).Empty(), true) or {
   err = &UserInputError{errors.New("color must be unique")}
   return
 }
 
 jsonResBody = &Tomate{ID: fmt.Sprintf("%v", backend.Len()), Color: color}
 backend.Push(jsonResBody)
 
 })

 return jsonResBody, err
}

>From that go compatible code,


// Create a new Tomate
func (t Controller) Create(postColor *string) (jsonResBody *Tomate, err 
error) {
if postColor == nil {
return nil, &UserInputError{errors.New("Missing color parameter")}
}
color := strings.TrimSpace(*postColor)
if color == "" {
return nil, &UserInputError{errors.New("color must not be empty")}
}
t.backend.Transact(func(backend *Tomates) {
exist := backend.Filter(FilterTomates.ByColor(color)).Len()
if exist > 0 {
err = &UserInputError{errors.New("color must be unique")}
return
}
jsonResBody = &Tomate{ID: fmt.Sprintf("%v", backend.Len()), Color: 
color}
backend.Push(jsonResBody)
})
return jsonResBody, err
}



On Wednesday, May 24, 2017 at 9:52:27 AM UTC+2, mhh...@gmail.com wrote:
>
> see the title, only for what s needed 
> Slice/Splice/Each/Map/First/Last/Reverse/Sort ect ect not len, for reason. 
> so interface system serves the userland by its definition of struct, and 
> the basic slice type provided by the language is fully operational, without 
> breaking, btw. i don t go further in evaluation, i leave that to the 
> reader, just trying to work decently.
>

-- 
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: idea: generic methods on slices with some generic type support []string.Map(string) []string => [].Map() []

2017-05-26 Thread mhhcbon
for the fun, 

I want to write
[]string{"hello}.Map(strings.ToUpper).Each(fmt.Println)

would not work, func param are incompatible.

let s apply static rules to convert it,

printS, err := conv(func(s string), fmt.Println) or panic(err)
[]string{"hello}.Map(strings.ToUpper).Each(printS)

Now it s possible.

And if one does a fmt.MustPrintln to get ride of the error while still 
handling it (recoverable)
rather than ignore it as of today, 
you can write that, and handle error via recover, 
or simply ignore it as in the previous ex.

printS, err := conv(func(s string), fmt.MustPrintln) or panic(err)

[]string{"hello}.Map(strings.ToUpper).Each(printS)



On Wednesday, May 24, 2017 at 9:52:27 AM UTC+2, mhh...@gmail.com wrote:
>
> see the title, only for what s needed 
> Slice/Splice/Each/Map/First/Last/Reverse/Sort ect ect not len, for reason. 
> so interface system serves the userland by its definition of struct, and 
> the basic slice type provided by the language is fully operational, without 
> breaking, btw. i don t go further in evaluation, i leave that to the 
> reader, just trying to work decently.
>

-- 
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: idea: generic methods on slices with some generic type support []string.Map(string) []string => [].Map() []

2017-05-26 Thread mhhcbon
or this,

printS, err := conv(func(s string, err error), fmt.Println) or panic(err)
_, err := []string{"hello}.Map(strings.ToUpper).MustEach(printS) or 
panic(err)

count, err := conv(func(n int), fmt.Println) or panic(err)
n := []string{"hello}.Map(strings.ToUpper).Sum(count)

count, err := conv(func(n int, err error), fmt.Println) or panic(err)
n, err := []string{"hello}.Map(strings.ToUpper).MustSum(count) or panic(err)

that'd be great...

On Friday, May 26, 2017 at 2:25:37 PM UTC+2, mhh...@gmail.com wrote:
>
> for the fun, 
>
> I want to write
> []string{"hello}.Map(strings.ToUpper).Each(fmt.Println)
>
> would not work, func param are incompatible.
>
> let s apply static rules to convert it,
>
> printS, err := conv(func(s string), fmt.Println) or panic(err)
> []string{"hello}.Map(strings.ToUpper).Each(printS)
>
> Now it s possible.
>
> And if one does a fmt.MustPrintln to get ride of the error while still 
> handling it (recoverable)
> rather than ignore it as of today, 
> you can write that, and handle error via recover, 
> or simply ignore it as in the previous ex.
>
> printS, err := conv(func(s string), fmt.MustPrintln) or panic(err)
>
> []string{"hello}.Map(strings.ToUpper).Each(printS)
>
>
>
> On Wednesday, May 24, 2017 at 9:52:27 AM UTC+2, mhh...@gmail.com wrote:
>>
>> see the title, only for what s needed 
>> Slice/Splice/Each/Map/First/Last/Reverse/Sort ect ect not len, for reason. 
>> so interface system serves the userland by its definition of struct, and 
>> the basic slice type provided by the language is fully operational, without 
>> breaking, btw. i don t go further in evaluation, i leave that to the 
>> reader, just trying to work decently.
>>
>

-- 
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: idea: generic methods on slices with some generic type support []string.Map(string) []string => [].Map() []

2017-05-26 Thread mhhcbon
oops... mistake in it.


printS, err := conv(func(s string, err error), fmt.Println) or panic(err)
_, err := []string{"hello}.Map(strings.
ToUpper).MustEach(printS) or panic(err)

count, err := conv(func(s string) n int, fmt.Println) or panic(err)
n := []string{"hello}.Map(strings.ToUpper).Sum(count)

count, err := conv(func(s string) (n int, err error), fmt.Println) or 
panic(err)
n, err := []string{"hello}.Map(strings.ToUpper).MustSum(count) or panic(err)

more like this, take advantage of return type and names to do more 
conversion.

On Friday, May 26, 2017 at 2:45:33 PM UTC+2, mhh...@gmail.com wrote:
>
> or this,
>
> printS, err := conv(func(s string, err error), fmt.Println) or panic(err)
> _, err := []string{"hello}.Map(strings.ToUpper).MustEach(printS) or 
> panic(err)
>
> count, err := conv(func(n int), fmt.Println) or panic(err)
> n := []string{"hello}.Map(strings.ToUpper).Sum(count)
>
> count, err := conv(func(n int, err error), fmt.Println) or panic(err)
> n, err := []string{"hello}.Map(strings.ToUpper).MustSum(count) or 
> panic(err)
>
> that'd be great...
>
> On Friday, May 26, 2017 at 2:25:37 PM UTC+2, mhh...@gmail.com wrote:
>>
>> for the fun, 
>>
>> I want to write
>> []string{"hello}.Map(strings.ToUpper).Each(fmt.Println)
>>
>> would not work, func param are incompatible.
>>
>> let s apply static rules to convert it,
>>
>> printS, err := conv(func(s string), fmt.Println) or panic(err)
>> []string{"hello}.Map(strings.ToUpper).Each(printS)
>>
>> Now it s possible.
>>
>> And if one does a fmt.MustPrintln to get ride of the error while still 
>> handling it (recoverable)
>> rather than ignore it as of today, 
>> you can write that, and handle error via recover, 
>> or simply ignore it as in the previous ex.
>>
>> printS, err := conv(func(s string), fmt.MustPrintln) or panic(err)
>>
>> []string{"hello}.Map(strings.ToUpper).Each(printS)
>>
>>
>>
>> On Wednesday, May 24, 2017 at 9:52:27 AM UTC+2, mhh...@gmail.com wrote:
>>>
>>> see the title, only for what s needed 
>>> Slice/Splice/Each/Map/First/Last/Reverse/Sort ect ect not len, for reason. 
>>> so interface system serves the userland by its definition of struct, and 
>>> the basic slice type provided by the language is fully operational, without 
>>> breaking, btw. i don t go further in evaluation, i leave that to the 
>>> reader, just trying to work decently.
>>>
>>

-- 
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] remove last index of character from string and also want use strings.LastIndex(s, sep string)

2017-05-26 Thread long . asyn
var str = "a/b/c/d/c"
// I want remove last chracter from str
var strRunes = []rune(str)
var newStrRunes = strRunes[0 : len(strRunes)-1]
// then I want get last index of chracters `/c`, I need convert 
to string back!???
strings.LastIndex(string(newStrRunes), "/c")
// Does there have a method that LastIndex(rs []rune, s string)

Thanks for your help!

-- 
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] remove last index of character from string and also want use strings.LastIndex(s, sep string)

2017-05-26 Thread messju mohr
Hi,

On Fri, May 26, 2017 at 07:10:43AM -0700, long.a...@gmail.com wrote:
>var str = "a/b/c/d/c"
>// I want remove last chracter from str
>var strRunes = []rune(str)
>var newStrRunes = strRunes[0 : len(strRunes)-1]
>// then I want get last index of chracters `/c`, I need 
> convert to string back!???
>strings.LastIndex(string(newStrRunes), "/c")
>// Does there have a method that LastIndex(rs []rune, s string)
>Thanks for your help!

You don't have to convert to a slice of runes:

var str = "a/b/c/d/c"
var newStr = str[0:len(str)-1]
fmt.Println(strings.LastIndex(newStr, "/c"))

Or you have to convert your slice back to a string:

var str = "a/b/c/d/c"
var strRunes = []rune(str)
var newStrRunes = strRunes[0 : len(strRunes)-1]
fmt.Println(strings.LastIndex(string(newStrRunes), "/c"))

HTH
messju

-- 
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] How fast can gopacket handles?

2017-05-26 Thread Chun Zhang
Hi, All, 

I am trying to write a small program to handle packets coming from a GigE 
wire. The testing code snip is as below. 

The problem I am facing is that this is extremely slow, can only handle up 
to 250Mbps-ish traffic with normal ipv4 sized packets, anything above that 
resulting significant packet drop.  Note that I am doing nothing with the 
packet at this moment. If I try to do any packet processing, then 
apparently it gets slower.

Has anybody measured the efficiency of the gopacket package? Is there any 
other faster alternatives?

PS: the host machine is an ubuntu VM with 12-core and 12G memory, but looks 
only 2 cores are used for this program. 

Thanks,
Chun



// Open device
handle, err = pcap.OpenLive(device, snapshot_len, promiscuous, timeout)
if err == nil {
   Info.Println("Open interface ", device, "successfully")

}
defer handle.Close()


   //fmt.Println("In the deafult reading case ", time.Now())
   // Use the handle as a packet source to process all packets
   packetSource := gopacket.NewPacketSource(handle, handle.LinkType())
   Info.Println("pcketsourc is ", packetSource, time.Now())
   for packet := range packetSource.Packets() {
  
Debug.Println("---")
  count++
  Warning.Println("packet count ", count)

  // write to a pcap for testing
  /*err = w.WritePacket(packet.Metadata().CaptureInfo, 
packet.Data())
  if err != nil {
 fmt.Println(err)
  }*/

  continue

-- 
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: How fast can gopacket handles?

2017-05-26 Thread Egon
As a baseline measurement I suggest writing the same code in C; this shows 
how much your VM / config / machine can handle.

With gopacket -- use src.NextPacket instead of Packets.

There are also: https://github.com/akrennmair/gopcap 
and https://github.com/miekg/pcap

+ Egon

On Friday, 26 May 2017 19:01:20 UTC+3, Chun Zhang wrote:
>
> Hi, All, 
>
> I am trying to write a small program to handle packets coming from a GigE 
> wire. The testing code snip is as below. 
>
> The problem I am facing is that this is extremely slow, can only handle up 
> to 250Mbps-ish traffic with normal ipv4 sized packets, anything above that 
> resulting significant packet drop.  Note that I am doing nothing with the 
> packet at this moment. If I try to do any packet processing, then 
> apparently it gets slower.
>
> Has anybody measured the efficiency of the gopacket package? Is there any 
> other faster alternatives?
>
> PS: the host machine is an ubuntu VM with 12-core and 12G memory, but 
> looks only 2 cores are used for this program. 
>
> Thanks,
> Chun
>
>
>
> // Open device
> handle, err = pcap.OpenLive(device, snapshot_len, promiscuous, timeout)
> if err == nil {
>Info.Println("Open interface ", device, "successfully")
>
> }
> defer handle.Close()
>
>
>//fmt.Println("In the deafult reading case ", time.Now())
>// Use the handle as a packet source to process all packets
>packetSource := gopacket.NewPacketSource(handle, handle.LinkType())
>Info.Println("pcketsourc is ", packetSource, time.Now())
>for packet := range packetSource.Packets() {
>   
> Debug.Println("---")
>   count++
>   Warning.Println("packet count ", count)
>
>   // write to a pcap for testing
>   /*err = w.WritePacket(packet.Metadata().CaptureInfo, 
> packet.Data())
>   if err != nil {
>  fmt.Println(err)
>   }*/
>
>   continue
>
>

-- 
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: How fast can gopacket handles?

2017-05-26 Thread Chun Zhang
Good point.  
as a comparison: tcpdump -w /dev/null can handle up to 750Mbps, where 
sending machine's  speed limit reached. I think it should be able to handle 
line rate.

Are those two packages lighter/faster than gopacket?


Thanks,
Chun

On Friday, May 26, 2017 at 12:37:55 PM UTC-4, Egon wrote:
>
> As a baseline measurement I suggest writing the same code in C; this shows 
> how much your VM / config / machine can handle.
>
> With gopacket -- use src.NextPacket instead of Packets.
>
> There are also: https://github.com/akrennmair/gopcap and 
> https://github.com/miekg/pcap
>
> + Egon
>
> On Friday, 26 May 2017 19:01:20 UTC+3, Chun Zhang wrote:
>>
>> Hi, All, 
>>
>> I am trying to write a small program to handle packets coming from a GigE 
>> wire. The testing code snip is as below. 
>>
>> The problem I am facing is that this is extremely slow, can only handle 
>> up to 250Mbps-ish traffic with normal ipv4 sized packets, anything above 
>> that resulting significant packet drop.  Note that I am doing nothing with 
>> the packet at this moment. If I try to do any packet processing, then 
>> apparently it gets slower.
>>
>> Has anybody measured the efficiency of the gopacket package? Is there any 
>> other faster alternatives?
>>
>> PS: the host machine is an ubuntu VM with 12-core and 12G memory, but 
>> looks only 2 cores are used for this program. 
>>
>> Thanks,
>> Chun
>>
>>
>>
>> // Open device
>> handle, err = pcap.OpenLive(device, snapshot_len, promiscuous, timeout)
>> if err == nil {
>>Info.Println("Open interface ", device, "successfully")
>>
>> }
>> defer handle.Close()
>>
>>
>>//fmt.Println("In the deafult reading case ", time.Now())
>>// Use the handle as a packet source to process all packets
>>packetSource := gopacket.NewPacketSource(handle, handle.LinkType())
>>Info.Println("pcketsourc is ", packetSource, time.Now())
>>for packet := range packetSource.Packets() {
>>   
>> Debug.Println("---")
>>   count++
>>   Warning.Println("packet count ", count)
>>
>>   // write to a pcap for testing
>>   /*err = w.WritePacket(packet.Metadata().CaptureInfo, 
>> packet.Data())
>>   if err != nil {
>>  fmt.Println(err)
>>   }*/
>>
>>   continue
>>
>>

-- 
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] Go Socket vs C Socket for single-threaded/single CPU socket programming

2017-05-26 Thread streckertdavid
 

This might be a silly question, but I’m going to ask anyway. I'm working on 
a High-Frequency Trading program for educational purposes. I don’t expect 
it to make money; it’s a fun project to learn about socket programming. 


It will be a single-threaded program running on one CPU that will “talk” to 
two different API endpoints at a currency brokerage firm called Oanda. 
Because the program will be single threaded, I don’t need to really take 
advantage of Go’s concurrency support. 


For a single-threaded/single CPU program, is there any reason to consider 
Go instead of C when speed is the most important consideration? Is there 
anything you’d recommend I think about? Any information is appreciated. 

-- 
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] Go Socket vs C Socket for single-threaded/single CPU socket programming

2017-05-26 Thread Steven Hartland
Why do you say it will be single threaded?

I ask as even with a single core multiple threads can be beneficial.

Even with GOMAXPROCS=1 the go runtime will  multiplex multiple requests
efficiently without you thinking about it.

On Fri, 26 May 2017 at 19:32,  wrote:

> This might be a silly question, but I’m going to ask anyway. I'm working
> on a High-Frequency Trading program for educational purposes. I don’t
> expect it to make money; it’s a fun project to learn about socket
> programming.
>
>
> It will be a single-threaded program running on one CPU that will “talk”
> to two different API endpoints at a currency brokerage firm called Oanda.
> Because the program will be single threaded, I don’t need to really take
> advantage of Go’s concurrency support.
>
>
> For a single-threaded/single CPU program, is there any reason to consider
> Go instead of C when speed is the most important consideration? Is there
> anything you’d recommend I think about? Any information is appreciated.
>
> --
> 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.


Re: [go-nuts] Go Socket vs C Socket for single-threaded/single CPU socket programming

2017-05-26 Thread streckertdavid
The brokerage firm's servers are in NYC. In order to get server co-location 
I’m considering renting our a virtual server in NYC from a company called 
Linode. Their servers start at $5 a month at this price point you get one 
CPU for your virtual server. 

I did not know multiple threads can be beneficial with a single core. 
However, I know next to nothing about multi threaded programming! I figured 
one thread would be good for the sake of simplicity. Are you saying that 
using multiple threads on a single core could result in a performance 
boost? Even for a very simple program? 

-- 
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] Go Socket vs C Socket for single-threaded/single CPU socket programming

2017-05-26 Thread Justin Israel
On Sat, May 27, 2017, 7:46 AM  wrote:

> The brokerage firm's servers are in NYC. In order to get server
> co-location I’m considering renting our a virtual server in NYC from a
> company called Linode. Their servers start at $5 a month at this price
> point you get one CPU for your virtual server.
>
> I did not know multiple threads can be beneficial with a single core.
> However, I know next to nothing about multi threaded programming! I figured
> one thread would be good for the sake of simplicity. Are you saying that
> using multiple threads on a single core could result in a performance
> boost? Even for a very simple program?
>

As an example, you said you want to talk to 2 different apis. Even on a
single cpu if you were to take advantage of running those tasks in their
own goroutines, when one task is blocked on io the other task can get
scheduled to run. Technically you can get the similar behavior in C with
threads getting a time slice on the cpu. But as you mentioned you don't
know multithreaded programming, in Go you would probably find it very
simple to organise your logic into concurrent goroutines. You just write
your code in a way that allows the Go scheduler to do its best for whatever
available amount of cpu cores are available.

-- 
> 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: Tooling experience feedback

2017-05-26 Thread E Leong
I'm trying to pass arguments to go test using 

go test -args -flag1 val1 -flag2 val2

Documentation doesn't explain how one can extract flag1 and flag2 or their 
values from within the test.
I am using os.Args to get to them, but that feels like a hack.

The only documentation I see right now 
in https://golang.org/cmd/go/#hdr-Description_of_testing_flags

go test -v -args -x -v


... the -x and the second -v are passed through to the test binary 
unchanged and with no effect on the go command itself. 

On Tuesday, October 18, 2016 at 11:54:49 AM UTC-7, Jaana Burcu Dogan wrote:
>
> Hello gophers,
>
> I am going to spend some time on improving the not-documented or 
> hard-to-use parts of the Go tools. I will mainly focus on go build and go 
> test. The work will consist of reorganizing manuals, proposing new 
> subcommands or flags to support commonly used multi-step things and so on.
>
> To give you some concrete examples:
>
> I have been in cases where users cannot find the build flags because they 
> are hidden. E.g.
>
> $ go test -help
> test [build/test flags] [packages] [build/test flags & test binary 
> flags]
> ...
>
> requires you to know about where the build flags are. Some tools are 
> invisible for the newcomers.
>
> The other example is about test coverage. It is so tedious that I need an 
> alias.
>
> func gocover() {
> go test -v -coverprofile=coverage.out && go tool cover 
> -html=coverage.out
> } 
>
> I want to learn more about your experience, aliases, etc to propose 
> improvements and work on the most commonly suggested items. I also am 
> planning to go through this mailing list, stack overflow and other channels 
> to see the common complaints.
>
> Feel free to reply to this thread or write to me privately.
>
> Thanks,
> JBD
>

-- 
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] Re: Tooling experience feedback

2017-05-26 Thread Ian Lance Taylor
On Fri, May 26, 2017 at 1:32 PM, E Leong  wrote:
>
> I'm trying to pass arguments to go test using
>
> go test -args -flag1 val1 -flag2 val2
>
> Documentation doesn't explain how one can extract flag1 and flag2 or their
> values from within the test.
> I am using os.Args to get to them, but that feels like a hack.
>
> The only documentation I see right now in
> https://golang.org/cmd/go/#hdr-Description_of_testing_flags
>
> go test -v -args -x -v
>
>
> ... the -x and the second -v are passed through to the test binary unchanged
> and with no effect on the go command itself.

If you want your test program to have flags, use the flag package
(https://golang.org/pkg/flags) to define the flags you want.

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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: How fast can gopacket handles?

2017-05-26 Thread Egon
On Friday, 26 May 2017 20:51:55 UTC+3, Chun Zhang wrote:
>
> Good point.  
> as a comparison: tcpdump -w /dev/null can handle up to 750Mbps, where 
> sending machine's  speed limit reached. I think it should be able to handle 
> line rate.
>
> Are those two packages lighter/faster than gopacket?
>

Nevermind, just noticed... gopacket/pcap is a fork of akrennmair/gopcap

Anyways, to get more information on what is taking time in your program 
see https://blog.golang.org/profiling-go-programs
 
Maybe try something like this:

handle, err := pcap.OpenLive(device, snapshot_len, promiscuous, timeout)
// ...
for {
data, ci, err := handle.ZeroCopyReadPacketData()
// ...


This should remove allocations from critical path.

*PS: code untested and may contain typos :P*
 

>
>
> Thanks,
> Chun
>
> On Friday, May 26, 2017 at 12:37:55 PM UTC-4, Egon wrote:
>>
>> As a baseline measurement I suggest writing the same code in C; this 
>> shows how much your VM / config / machine can handle.
>>
>> With gopacket -- use src.NextPacket instead of Packets.
>>
>> There are also: https://github.com/akrennmair/gopcap and 
>> https://github.com/miekg/pcap
>>
>> + Egon
>>
>> On Friday, 26 May 2017 19:01:20 UTC+3, Chun Zhang wrote:
>>>
>>> Hi, All, 
>>>
>>> I am trying to write a small program to handle packets coming from a 
>>> GigE wire. The testing code snip is as below. 
>>>
>>> The problem I am facing is that this is extremely slow, can only handle 
>>> up to 250Mbps-ish traffic with normal ipv4 sized packets, anything above 
>>> that resulting significant packet drop.  Note that I am doing nothing with 
>>> the packet at this moment. If I try to do any packet processing, then 
>>> apparently it gets slower.
>>>
>>> Has anybody measured the efficiency of the gopacket package? Is there 
>>> any other faster alternatives?
>>>
>>> PS: the host machine is an ubuntu VM with 12-core and 12G memory, but 
>>> looks only 2 cores are used for this program. 
>>>
>>> Thanks,
>>> Chun
>>>
>>>
>>>
>>> // Open device
>>> handle, err = pcap.OpenLive(device, snapshot_len, promiscuous, timeout)
>>> if err == nil {
>>>Info.Println("Open interface ", device, "successfully")
>>>
>>> }
>>> defer handle.Close()
>>>
>>>
>>>//fmt.Println("In the deafult reading case ", time.Now())
>>>// Use the handle as a packet source to process all packets
>>>packetSource := gopacket.NewPacketSource(handle, handle.LinkType())
>>>Info.Println("pcketsourc is ", packetSource, time.Now())
>>>for packet := range packetSource.Packets() {
>>>   
>>> Debug.Println("---")
>>>   count++
>>>   Warning.Println("packet count ", count)
>>>
>>>   // write to a pcap for testing
>>>   /*err = w.WritePacket(packet.Metadata().CaptureInfo, 
>>> packet.Data())
>>>   if err != nil {
>>>  fmt.Println(err)
>>>   }*/
>>>
>>>   continue
>>>
>>>

-- 
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: Go Socket vs C Socket for single-threaded/single CPU socket programming

2017-05-26 Thread Egon
On Friday, 26 May 2017 21:32:43 UTC+3, David Streckert wrote:
>
> This might be a silly question, but I’m going to ask anyway. I'm working 
> on a High-Frequency Trading program for educational purposes. I don’t 
> expect it to make money; it’s a fun project to learn about socket 
> programming. 
>
>
> It will be a single-threaded program running on one CPU that will “talk” 
> to two different API endpoints at a currency brokerage firm called Oanda. 
> Because the program will be single threaded, I don’t need to really take 
> advantage of Go’s concurrency support. 
>
>
> For a single-threaded/single CPU program, is there any reason to consider 
> Go instead of C when speed is the most important consideration?
>

When speed is the most important consideration, then Go is not the best 
option... And, yes... C, C++, asm, Fortran, O'Caml are all better options 
in that case. 

But... I don't want to write asm nor Fortran (at least not most of the 
time)... Life's too short for that.

Also, even if you build the fastest possible server to handle these things 
and you don't have a good location and have a 10ms latency... then the 
0.001ms vs 0.03ms server computation won't make a big difference 
(probably). There's more to HFT than just the software.

Is there anything you’d recommend I think about? Any information is 
> appreciated.
>

Think about what you want from this project, do you want to:

1. understand how low latency programming is done -- maybe using HFT isn't 
necessary to learn this
2. understand how trading apis work and are put together -- you could try 
slow trading instead
3. understand how predicting works -- you could analyse and try to predict 
on offline data
4. something else ...

i.e. figure out what exactly you want to learn and use the best tool for 
the job...

+ Egon

-- 
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] How do you pass around an HTTP response?

2017-05-26 Thread ask dev
If I delegate the handling of a request, but still want information about 
the response (status code, compressed, content length). 
How should that information be returned without risk of leaving the 
connection open?

Close the response body and return the response?
Close the response, transfer the information and return it in a separate 
data structure?

-- 
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] remove last index of character from string and also want use strings.LastIndex(s, sep string)

2017-05-26 Thread long . asyn
Thanks for your reply. the `str[0:len(str)-1]` not work for NO ascii 
chracters.

https://play.golang.org/p/7i6-3Zcy36



On Friday, May 26, 2017 at 11:06:10 PM UTC+8, messju mohr wrote:
>
> Hi, 
>
> On Fri, May 26, 2017 at 07:10:43AM -0700, long...@gmail.com  
> wrote: 
> >var str = "a/b/c/d/c" 
> >// I want remove last chracter from str 
> >var strRunes = []rune(str) 
> >var newStrRunes = strRunes[0 : len(strRunes)-1] 
> >// then I want get last index of chracters `/c`, I need 
> convert to string back!??? 
> >strings.LastIndex(string(newStrRunes), "/c") 
> >// Does there have a method that LastIndex(rs []rune, s 
> string) 
> >Thanks for your help! 
>
> You don't have to convert to a slice of runes: 
>
> var str = "a/b/c/d/c" 
> var newStr = str[0:len(str)-1] 
> fmt.Println(strings.LastIndex(newStr, "/c")) 
>
> Or you have to convert your slice back to a string: 
>
> var str = "a/b/c/d/c" 
> var strRunes = []rune(str) 
> var newStrRunes = strRunes[0 : len(strRunes)-1] 
> fmt.Println(strings.LastIndex(string(newStrRunes), "/c")) 
>
> HTH 
> messju 
>

-- 
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: remove last index of character from string and also want use strings.LastIndex(s, sep string)

2017-05-26 Thread long . asyn
I find the method like:

package main


import (
 "fmt"
 "strings"
 "unicode/utf8"
)


func main() {
 var str = "a/b/汉字/d/汉字"
 var _, size = utf8.DecodeLastRuneInString(str)
 // Does `str[0:len(str)-size]` have memory copy? 
 var i = strings.LastIndex(str[0:len(str)-size], "/汉字")
 fmt.Println(i)
}



But I don't know if str[0:len(str)-size] if copy the string? If the code 
will copy the string, I will covert the string to []byte first. Because I 
need several times check for the str.
Where I can find some article about that(str copy)?


On Friday, May 26, 2017 at 10:45:09 PM UTC+8, long...@gmail.com wrote:
>
> var str = "a/b/c/d/c"
> // I want remove last chracter from str
> var strRunes = []rune(str)
> var newStrRunes = strRunes[0 : len(strRunes)-1]
> // then I want get last index of chracters `/c`, I need 
> convert to string back!???
> strings.LastIndex(string(newStrRunes), "/c")
> // Does there have a method that LastIndex(rs []rune, s 
> string)
>
> Thanks for your help!
>

-- 
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] Re: remove last index of character from string and also want use strings.LastIndex(s, sep string)

2017-05-26 Thread Rob Pike
blog.golang.org/slices and blog.golang.org/strings

-rob


On Sat, May 27, 2017 at 11:14 AM,  wrote:

> I find the method like:
>
> package main
>
>
> import (
>  "fmt"
>  "strings"
>  "unicode/utf8"
> )
>
>
> func main() {
>  var str = "a/b/汉字/d/汉字"
>  var _, size = utf8.DecodeLastRuneInString(str)
>  // Does `str[0:len(str)-size]` have memory copy?
>  var i = strings.LastIndex(str[0:len(str)-size], "/汉字")
>  fmt.Println(i)
> }
>
>
>
> But I don't know if str[0:len(str)-size] if copy the string? If the code
> will copy the string, I will covert the string to []byte first. Because I
> need several times check for the str.
> Where I can find some article about that(str copy)?
>
>
> On Friday, May 26, 2017 at 10:45:09 PM UTC+8, long...@gmail.com wrote:
>>
>> var str = "a/b/c/d/c"
>> // I want remove last chracter from str
>> var strRunes = []rune(str)
>> var newStrRunes = strRunes[0 : len(strRunes)-1]
>> // then I want get last index of chracters `/c`, I need
>> convert to string back!???
>> strings.LastIndex(string(newStrRunes), "/c")
>> // Does there have a method that LastIndex(rs []rune, s
>> string)
>>
>> Thanks for your help!
>>
> --
> 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.