0

I'm working on a giant dictionary of words -> language, the data for which I have, but what I need is to have one thread running a daemon, written in Go, which keeps all of this in memory (yes, I have that much memory too) and is "callable" by other Go apps.

I'm sure this is a standard type of thing to do, but to be honest I've never attempted such a thing before and am not familiar enough to know where to find information on how to do this.

Having it run as a daemon is easy. My problem is what is an efficient way of calling this app from another Go app, which will need to be done many millions of times.

I'm thinking something along the lines of:

connection, err := InitateConnectionToApp()
for _, someword := range mysliceofstrings {
    languageofword := connection.FindIt(someword)
}

Then the daemon somehow receives this request, looks up the value in its map and delivers it back.

I hope that makes sense. I have tried looking on Google but there is nothing I can find specific to Go.

If anyone can tell me where to start that would be great.

3
  • maybe just start by exposing an http api?
    – JimB
    Aug 1, 2014 at 18:44
  • I think you're looking for something like reddis
    – OneOfOne
    Aug 2, 2014 at 0:41
  • No, I am looking to make something like reddis.
    – Alasdair
    Aug 2, 2014 at 4:45

1 Answer 1

1

You could use RPC Go's standard Remote Procedure Call package.

Just Expose your api and then create a client to invoke the method remotely.

Simple example copy pasted from the docs:

package server

type Args struct {
    A, B int
}

type Quotient struct {
    Quo, Rem int
}

type Arith int

func (t *Arith) Multiply(args *Args, reply *int) error {
    *reply = args.A * args.B
    return nil
}

func (t *Arith) Divide(args *Args, quo *Quotient) error {
    if args.B == 0 {
        return errors.New("divide by zero")
    }
    quo.Quo = args.A / args.B
    quo.Rem = args.A % args.B
    return nil
}

func main() {
 arith := new(Arith)
 rpc.Register(arith)
 rpc.HandleHTTP()
 l, e := net.Listen("tcp", ":1234")
 if e != nil {
    log.Fatal("listen error:", e)
 }
 go http.Serve(l, nil)
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.