Esempio n. 1
0
func msetTestSingle(ch chan bool, cn, n int) error {
	var err error
	addr := utils.Addrcat(host, port)
	conn, err := redis.DialTimeout("tcp", addr, 0, 1*time.Second, 1*time.Second)
	if err != nil {
		log.Printf("redis conn error: %s", err)
		return err
	}
	defer conn.Close()
	v := make([]byte, dataSize)
	b := make([]interface{}, bucket+1)
	b[0] = topicName
	for i := 1; i < bucket+1; i++ {
		b[i] = v
	}
	count := n / bucket
	for i := 0; i < count; i++ {
		start := time.Now()
		_, err = conn.Do("MSET", b...)
		if err != nil {
			log.Printf("set error: c%d %v", cn, err)
		} else {
			end := time.Now()
			duration := end.Sub(start).Seconds()
			log.Printf("set succ: %s spend: %.3fms", topicName, duration*1000)
		}
	}
	ch <- true
	return nil
}
Esempio n. 2
0
func getTestSingle(ch chan bool, cn, n int) error {
	addr := utils.Addrcat(host, port)
	conn, err := redis.DialTimeout("tcp", addr, 0, 1*time.Second, 1*time.Second)
	if err != nil {
		log.Printf("redis conn error: %s", err)
		return err
	}
	defer conn.Close()
	key := topicName + "/" + lineName
	for i := 0; i < n; i++ {
		start := time.Now()
		reply, err := conn.Do("GET", key)
		if err != nil {
			log.Printf("get error: c%d %v", cn, err)
		} else {
			rpl, err := redis.Strings(reply, err)
			if err != nil {
				fmt.Printf("redis.values error: c%d %v\n", cn, err)
				return err
			}
			// fmt.Printf("redis.strings %v\n", v)
			end := time.Now()
			duration := end.Sub(start).Seconds()
			id := rpl[1]
			log.Printf("get succ: %s spend: %.3fms", id, duration*1000)
		}
	}
	ch <- true
	return nil
}
Esempio n. 3
0
// NewHTTPEntry returns a new HTTPEntry server
func NewHTTPEntry(host string, port int, messageQueue queue.MessageQueue) (*HTTPEntry, error) {
	h := new(HTTPEntry)

	addr := utils.Addrcat(host, port)
	server := new(http.Server)
	server.Addr = addr
	server.Handler = h

	h.host = host
	h.port = port
	h.server = server
	h.messageQueue = messageQueue

	return h, nil
}
Esempio n. 4
0
func setTest(c, n int) {
	ch := make(chan bool)
	conn := utils.Addrcat(host, port)
	mc := memcache.New(conn)
	singleCount := n / c
	for i := 0; i < c; i++ {
		go setTestSingle(ch, mc, i, singleCount)
	}
	for i := 0; i < c; i++ {
		select {
		case <-ch:
			log.Printf("set single succ: %s - c%d", topicName, i)
		}
	}
}
Esempio n. 5
0
// ListenAndServe implements the ListenAndServe interface
func (h *HTTPEntry) ListenAndServe() error {
	addr := utils.Addrcat(h.host, h.port)
	l, err := net.Listen("tcp", addr)
	if err != nil {
		return err
	}

	stopListener, err := utils.NewStopListener(l)
	if err != nil {
		return err
	}
	h.stopListener = stopListener

	log.Printf("http entrance serving at %s...", addr)
	return h.server.Serve(h.stopListener)
}
Esempio n. 6
0
// ListenAndServe implements the ListenAndServe interface
func (s *UnitedAdmin) ListenAndServe() error {
	addr := utils.Addrcat(s.host, s.port)
	l, err := net.Listen("tcp", addr)
	if err != nil {
		return err
	}

	stopListener, err := utils.NewStopListener(l)
	if err != nil {
		return err
	}
	s.stopListener = stopListener

	log.Printf("admin server serving at %s...", addr)
	return s.server.Serve(s.stopListener)
}
Esempio n. 7
0
func initQueue() {
	var mc *memcache.Client
	conn := utils.Addrcat(host, port)
	mc = memcache.New(conn)

	err := mc.Add(&memcache.Item{Key: topicName, Value: []byte{}})
	if err != nil {
		log.Printf("add error: %v", err)
	}

	fullLineName := topicName + "/" + lineName
	err = mc.Add(&memcache.Item{Key: fullLineName, Value: []byte{}})
	if err != nil {
		log.Printf("add error: %v", err)
	}
}
Esempio n. 8
0
func setTestSingle(ch chan bool, cn, n int) {
	var err error
	var mc *memcache.Client
	conn := utils.Addrcat(host, port)
	v := make([]byte, dataSize)
	mc = memcache.New(conn)
	for i := 0; i < n; i++ {
		start := time.Now()
		err = mc.Set(&memcache.Item{Key: topicName, Value: v})
		if err != nil {
			log.Printf("set error: c%d %v", cn, err)
		} else {
			end := time.Now()
			duration := end.Sub(start).Seconds()
			log.Printf("set succ: %s spend: %.3fms", topicName, duration*1000)
		}
	}
	ch <- true
}
Esempio n. 9
0
func getTestSingle(ch chan bool, cn, n int) {
	var mc *memcache.Client
	conn := utils.Addrcat(host, port)
	key := topicName + "/" + lineName
	keys := []string{key, "id"}
	mc = memcache.New(conn)
	for i := 0; i < n; i++ {
		start := time.Now()
		items, err := mc.GetMulti(keys)
		if err != nil {
			log.Printf("get error: c%d %v", cn, err)
		} else {
			end := time.Now()
			duration := end.Sub(start).Seconds()
			id := string(items["id"].Value)
			log.Printf("get succ: %s spend: %.3fms", id, duration*1000)
		}
	}
	ch <- true
}
Esempio n. 10
0
// NewUnitedAdmin returns a UnitedAdmin
func NewUnitedAdmin(host string, port int, messageQueue queue.MessageQueue) (*UnitedAdmin, error) {
	s := new(UnitedAdmin)

	s.adminMux = map[string]func(http.ResponseWriter, *http.Request, string){
		"/stat":  s.statHandler,
		"/empty": s.emptyHandler,
		"/rm":    s.rmHandler,
	}

	addr := utils.Addrcat(host, port)
	server := new(http.Server)
	server.Addr = addr
	server.Handler = s

	s.host = host
	s.port = port
	s.server = server
	s.messageQueue = messageQueue

	return s, nil
}
Esempio n. 11
0
// ListenAndServe implements the ListenAndServe interface
func (r *RedisEntry) ListenAndServe() error {
	addr := utils.Addrcat(r.host, r.port)
	l, err := net.Listen("tcp", addr)
	if err != nil {
		return err
	}

	stopListener, err := utils.NewStopListener(l)
	if err != nil {
		return err
	}
	r.stopListener = stopListener

	log.Printf("redis entrance serving at %s...", addr)
	for {
		conn, err := r.stopListener.Accept()
		if err != nil {
			// log.Printf("Accept failed: %s\n", err)
			return err
		}
		go r.handlerConn(newSession(conn))
	}
}
Esempio n. 12
0
func initQueue() error {
	addr := utils.Addrcat(host, port)
	conn, err := redis.DialTimeout("tcp", addr, 0, 1*time.Second, 1*time.Second)
	if err != nil {
		log.Printf("redis conn error: %s", err)
		return err
	}
	defer conn.Close()

	_, err = conn.Do("ADD", topicName)
	if err != nil {
		log.Printf("add error: %v", err)
		return err
	}

	fullLineName := topicName + "/" + lineName
	_, err = conn.Do("ADD", fullLineName)
	if err != nil {
		log.Printf("add error: %v", err)
		return err
	}
	return nil
}
Esempio n. 13
0
File: uQueue.go Progetto: jnan77/uq
// NewUnitedQueue returns a new UnitedQueue
func NewUnitedQueue(storage store.Storage, ip string, port int, etcdServers []string, etcdKey string) (*UnitedQueue, error) {
	topics := make(map[string]*topic)
	etcdStop := make(chan bool)
	uq := new(UnitedQueue)
	uq.topics = topics
	uq.storage = storage
	uq.etcdStop = etcdStop

	if len(etcdServers) > 0 {
		selfAddr := utils.Addrcat(ip, port)
		uq.selfAddr = selfAddr
		etcdClient := etcd.NewClient(etcdServers)
		uq.etcdClient = etcdClient
		uq.etcdKey = etcdKey
	}

	err := uq.loadQueue()
	if err != nil {
		return nil, err
	}

	go uq.etcdRun()
	return uq, nil
}
Esempio n. 14
0
// ListenAndServe implements the ListenAndServe interface
func (m *McEntry) ListenAndServe() error {
	addr := utils.Addrcat(m.host, m.port)
	l, err := net.Listen("tcp", addr)
	if err != nil {
		return err
	}

	stopListener, err := utils.NewStopListener(l)
	if err != nil {
		return err
	}
	m.stopListener = stopListener

	log.Printf("mc entrance serving at %s...", addr)
	for {
		conn, e := m.stopListener.Accept()
		if e != nil {
			// log.Printf("Accept failed: %s\n", e)
			return e
		}

		go m.handlerConn(conn)
	}
}