Example #1
0
func shutdown() {
	log.Println("Start shutdown (ie etcd cleanup)")
	option, err := ncsp.Config.GetOption("etcd.machines")
	ncsp.ErrCheckFatal(err, "Configuration error")
	machines := ncsp.ToEtcdMachinesList(option.([]interface{}))
	c := etcd.NewClient(machines)
	_, err = c.Get("/ncsp", false, false)
	if err != nil {
		if ncsp.EtcdErrorCode(err) != 100 {
			log.Fatal(err, "Get failed")
		}
	} else {
		_, err = c.Delete("/ncsp", true)
		ncsp.ErrCheckFatal(err, "Cannot delete")
	}
	log.Println("Shutdown done and etcd has been cleaned up")
}
Example #2
0
func prepare() {
	// cleanup
	ncsp.Config.Init("conf.json")
	option, err := ncsp.Config.GetOption("etcd.machines")
	ncsp.ErrCheckFatal(err, "Configuration error")
	machines := ncsp.ToEtcdMachinesList(option.([]interface{}))
	c := etcd.NewClient(machines)
	err = c.SetConsistency(etcd.STRONG_CONSISTENCY) // TODO: is this valid for other clients as well?
	ncsp.ErrCheckFatal(err, "Consistency")
	_, err = c.Get("/ncsp", false, false)
	if err != nil {
		if ncsp.EtcdErrorCode(err) != 100 {
			log.Fatal(err, "Get failed")
		}
	} else {
		_, err = c.Delete("/ncsp", true)
		ncsp.ErrCheckFatal(err, "Cannot delete")
	}
	_, err = c.CreateDir("/ncsp/", 0)
	ncsp.ErrCheckFatal(err, "Creating root dir")
}
Example #3
0
func sender_many_many_process2(chs []*ncsp.SenderChannel, n int, how_many int, done chan bool, objects [][]byte) {
	log.Println("Sender process")
	for i := 0; i < how_many; i++ {
		go func(n int, i int, done chan bool, objects [][]byte) {
			for j := 0; j < n; j++ {
				// add a unique ID here
				msg := new(bytes.Buffer)
				_, err := msg.WriteRune(rune(i*n + j))
				ncsp.ErrCheckFatal(err, "Write buffer error")
				_, err = msg.Write(objects[i*n+j])
				ncsp.ErrCheckFatal(err, "Write buffer error")
				if chs[i] == nil {
					log.Fatal("no channel")
				}
				err = chs[i].Send(msg)
				ncsp.ErrCheckFatal(err, "I'm not expeting this in this test")
			}
			done <- true
			chs[i].Close()
		}(n, i, done, objects)
	}
}
Example #4
0
func receiver_many_many_process2(chs []*ncsp.ReceiverChannel, n int, how_many int, done chan bool, table map[int][sha1.Size]byte) {
	log.Println("Receiver process")
	for i := 0; i < how_many; i++ {
		go func(ch *ncsp.ReceiverChannel, done chan bool, table map[int][sha1.Size]byte) {
			for j := 0; j < n; j++ {
				resp, err := ch.Receive()
				ncsp.ErrCheckFatal(err, "Receive failed")
				_, _, err = resp.ReadRune()
				ncsp.ErrCheckFatal(err, "Failed reading")
				// if len(resp.Bytes()) != 16 {
				// 	log.Fatal("received #", len(resp.Bytes()), "bytes")
				// }
				// sha := sha1.Sum(resp.Bytes())
				// for k := range sha {
				// 	if table[int(id)][k] != sha[k] {
				// 		log.Fatal("Receivd wrong data - id:", int(id), "k: ", k, " sha[i]: ", sha[k], "table[id][k]: ", table[int(id)][k])
				// 	}
				// }
			}
			done <- true
			ch.Close()
		}(chs[i], done, table)
	}
}
Example #5
0
func main() {
	go func() {
		log.Println(http.ListenAndServe("localhost:6060", nil))
	}()
	var how_many int
	var n int
	flag.IntVar(&how_many, "how_many", 2, "How many sockets")
	flag.IntVar(&n, "n", 10, "Number of requests per socket")
	flag.Parse()
	log.Println("how_many:", how_many)
	log.Println("n:", n)
	prepare()
	done := make(chan bool)

	// generate files
	objects := make([][]byte, how_many*n)
	table := make(map[int][sha1.Size]byte)
	for i := 0; i < how_many*n; i++ {
		objects[i] = make([]byte, 16)
		_, err := rand.Read(objects[i])
		ncsp.ErrCheckFatal(err, "Random number error")
		table[i] = sha1.Sum(objects[i])
	}

	// build sender channels
	senders := make([]*ncsp.SenderChannel, how_many)
	for i := range senders {
		senders[i] = ncsp.NewSenderChannel()
		opts := ncsp.NewOptions()
		opts.AddOption("buffer", reflect.Uint32)
		opts.SetOption("buffer", 0)
		// log.Println("building sender ", i)
		err := senders[i].Build("channel"+strconv.Itoa(i), opts)
		ncsp.ErrCheckFatal(err, "Cannot build sender channel")
	}
	// build receiver channels
	receivers := make([]*ncsp.ReceiverChannel, how_many)
	for i := range receivers {
		receivers[i] = ncsp.NewReceiverChannel()
		opts := ncsp.NewOptions()
		opts.AddOption("buffer", reflect.Uint32)
		opts.SetOption("buffer", 0)
		// log.Println("building receiver ", i)
		err := receivers[i].Build("channel"+strconv.Itoa(i), opts)
		ncsp.ErrCheckFatal(err, "Cannot build receiver channel")
	}

	log.Println("Starting test")
	start := time.Now()
	go sender_many_many_process2(senders, n, how_many, done, objects)
	go receiver_many_many_process2(receivers, n, how_many, done, table)
	for j := 0; j < 2*how_many; j++ {
		<-done
		// log.Println("---> Done", j)
	}
	end := time.Now()
	log.Println("Ending test")
	elapsed := end.Sub(start)
	log.Println("Time elapsed [ms]:", float64(elapsed)/1e6, "Req/s:", float64(how_many)*float64(n)/float64(elapsed)*1e9)
	log.Println("---> Shutting down")

	shutdown()
}