Viacheslav Biriukov | 21 Aug 21:46 2014
Picon

ReverseProxy performance and GC

Hello,

ReverseProxy from net/http/httputil shows strange performance issue. 
Performance drops to 1k RPS with GC enabled (by default). And with turned of (export GOGC="off") I could get 3,5k RPS. 

It looks like a code issue. There is no 100% CPU and context switching is low. I can't find it by my self.

It's easy to reproduce using code from example (for instance http://siberianlaika.ru/node/29). 

Does somebody have any ideas how to improve this?. 

--
Viacheslav Biriukov
BR

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Aiden | 21 Aug 21:42 2014
Picon

Interface definitions

Hi all,

I'm trying to wrap my head around interface usage. Am I correct in thinking each package defines interfaces as that package sees the world and what
it expects from values being passed in? Such that packages don't import eachother's interfaces, they just declare their own interfaces/world view?

Simple example, two packages Cat and Mouse. We want the safety of their interaction, but don't want to tie them together so:

/* cat.go */
type
Prayer interface {
   
Kill()
   
Eat()
   
Weight() int
}

type
Cat struct {
    munched
int
}
func
(c Cat) ChasePray( p Prayer ) {
    p
.Kill()
    p
.Eat()
    c
.munched += p.Weight()
}

/* mouse.go */
type
Preditorer interface {
   
ChasePray(Mouse)
}
// Mouse definition using Preditorer, implementing Prayer without referencing it in this package directly ...




so when we define a Mouse, providing it meets the Prayer interface the whole thing works. But what we don't do is define a general
preditor in cat.go and import that in mouse.go, we define the preditor interface in mouse.go in terms of what the mouse expects a preditor to be.

I know it's a weak example!

Is this right in terms of best practice? We keep expectations inside the package that expects certain conventions, even if that means defining
interfaces that are the same/redundant (maybe partially) in each package?

Just want to make sure i'm approaching it right.

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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Chris Kastorff | 21 Aug 19:08 2014
Picon

Comparing interface values initialized with typed variables with nil

http://play.golang.org/p/7bt8mlFDmi

This is a simplified case of an API wrapper that I'm writing.

In this wrapper, the generic layer uses interface{} for its optional
return values (which it passes to json.Unmarshal). However, the concrete
layer takes concrete types (e.g. *Node) as arguments and passes them to
the generic layer. In this way, the typed nil argument becomes an
interface{} with nil value and non-nil type when passed to the generic
layer; thus causing i == nil to return false even when the *Node
argument was nil.

Is there a better/cleaner way than
	i == nil || reflect.ValueOf(i).IsNil()
to see if the dynamic value of an interface{} is nil, ignoring its type?

    -Chris K

--

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

Juan Espinoza | 21 Aug 18:33 2014
Picon

Generalize a method (mgo)

I'm trying to get getObj() function will be more general and could work with any type, not only User like in my code. I was thinking in return a interface instead a defined struct, but I can't fit this idea to my code, please could someone give me a hand with this? 
Thanks in advance

type User struct { FirstName string `bson:"first_name"` LastName string `bson:"last_name"` } type Mbase struct { coll *mgo.Collection sess *mgo.Session } func (b *Mbase) getObj(attr string, val string) (res *User, err error) { err = b.coll.Find(bson.M{attr: val}).One(&res) if err != nil { return } err = nil return }

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Davide Moriello | 21 Aug 16:58 2014
Picon

Unescape html strings

Hi, how is possible to unescape strings? I have a query from the database that read an array of articles in a struct

type Blog struct {
Id int
Title string
Date int
Author string
ImgHome string
TestoCorto string
TestoLungo string

}

In the database there are some html strings for the article and when I output all articles

this.Data["blogs"] = models.GetAllBlogs()


every html get escaped :-( I have to unescape the arrays. How can I do it?


Thank you!


PS: i'm using beego, but there should be any difference... I think

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
phiroc | 21 Aug 16:32 2014
Picon

Passing values to Walk Function

Hello,

I am using filepath.Walk as follows to visit files in a directory.

filepath.Walk(directory_root, VisitFile)

Is there a way to pass values to VisitFile, other than by using global variables?

Many thanks.

Philippe

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
bernard | 21 Aug 04:04 2014

Why no "class" keyword in Go?

I'm new to Go. It seems to me that it complicates things by simply not allowing us to define classes like in most other language. Am I missing something fundamental here?


For instance, here's how to declare a "class" in Go.


type
MyClass struct {
 
var name string
 
var id  integer
}


func
(c *MyClass) DoSomethingWithName() error {
  c
.name = "foo"
}


func
(c *MyClass) DoSomethingWithId() error {
  c
.id = "1010"
}



Why didn't the designer simply encapsulate that into a proper class?
Eg: 

class MyClass {
 
var name string
 
var id  integer
 
DoSomethingWithName() error {
    name
= "foo"
 
}
 
DoSomethingWithId() error {
    id
= "1010"
 
}
}

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Paweł Borkowski | 21 Aug 16:07 2014
Picon

Golang test suffixes

When I am running multiple tests (e.g go test -v ./...) some of my tests end up with suffixes:
TestFooBar-16
TestFooBaz-16
It looks like it's coming from the value of GOMAXPROCS (when GOMAXPROCS != 1). Can anyone confirm?

My init function:
func init() {
log.SetFlags(log.Ltime | log.Lmicroseconds | log.Lshortfile)
runtime.GOMAXPROCS(16)
}

Does setting GOMAXPROCS in the init functions makes tests run parallel (I didn't mark any of the tests as parallel explicitly)?
Can anyone point me to golang doc where I could read details about 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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Artem Andreenko | 21 Aug 14:27 2014
Picon

Json Marshal Bug

Hello!


I have to programs:


package main

import "log"
import "encoding/json"

type Acc struct {
Amount int64 `json:"amount,string"`
}

func main() {
var amount int64 = 100500
test := Acc{Amount: amount}
data, _ := json.Marshal(&test)
log.Printf("%s", string(data))
}

Output: 2009/11/10 23:00:00 {"amount":"100500"}


package main

import "log"
import "encoding/json"

type Acc struct {
Amount *int64 `json:"amount,string"`
}

func main() {
var amount int64 = 100500
test := Acc{Amount: &amount}
data, _ := json.Marshal(&test)
log.Printf("%s", string(data))
}

Output: 2009/11/10 23:00:00 {"amount":100500}

Latest program don't wrap amount value in quotes.

Regards,
Artem Andreenko.

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Joshua Liebow-Feeser | 21 Aug 14:14 2014
Picon

Source code highlighting links on golang.org

At present, when you click on a function or type in the golang.org/pkg documentation, it brings you to the source file with the relevant source code highlighted. However, these links are relative to the current published source, and when a source file changes, the links become invalid (often pointing to the wrong line or highlighting the wrong parts of lines). In light of the fact that references to source code are all over the internet (especially in programming forums like StackOverflow), might it be a good idea to have these links instead be permalinks to that version of the file, or at least have some way to get a permalink instead of a relative link for these sorts of purposes?

Cheers,
Josh

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Matt Joiner | 21 Aug 12:35 2014
Picon

Passing configuration structs

I have a function NewServer that takes a configuration struct *Config. NewServer(*Config) (*Server, error). Is it better to pass this config as a pointer type or as a copied value a la NewServer(Config)? Why?

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.

Gmane