Пример #1
0
func createUdsClients() {
	socket, err := thrift.NewTSocketTimeout(hostUds, 1*time.Second)
	if err != nil {
		log.Fatal("uds socket error:", err)
	}
	transport := thrift.NewTBufferedTransport(socket, 10240)
	inputProtocol := thrift.NewTBinaryProtocolTransport(transport)
	outputProtocol := thrift.NewTMultiplexedProtocol(inputProtocol, "userManager")
	userManagerClient := services.NewUserManagerClientProtocol(transport, inputProtocol, outputProtocol)
	if err := transport.Open(); err != nil {
		log.Fatal("uds transport open error[userManager]:", err)
	}
	userManagerClients <- userManagerClient

	socket, err = thrift.NewTSocketTimeout(hostUds, 1*time.Second)
	if err != nil {
		log.Fatal("uds socket error:", err)
	}
	transport = thrift.NewTBufferedTransport(socket, 10240)
	inputProtocol = thrift.NewTBinaryProtocolTransport(transport)
	outputProtocol = thrift.NewTMultiplexedProtocol(inputProtocol, "groupManager")
	groupManagerClient := services.NewGroupManagerClientProtocol(transport, inputProtocol, outputProtocol)
	if err := transport.Open(); err != nil {
		log.Fatal("uds transport open error[groupManager]:", err)
	}
	groupManagerClients <- groupManagerClient
}
Пример #2
0
func main() {

	fmt.Println("Hello World!")
	log.SetFlags(log.Ldate | log.Lmicroseconds)

	for i := 0; i < cap(clientsPool); i++ {
		socket, err := thrift.NewTSocketTimeout(hostUds, 1*time.Second)
		if err != nil {
			log.Fatal("uds socket error:", err)
		}
		transport := thrift.NewTBufferedTransport(socket, 10240)
		inputProtocol := thrift.NewTBinaryProtocolTransport(transport)
		outputProtocol := thrift.NewTMultiplexedProtocol(inputProtocol, "userManager")
		userManagerClient := services.NewUserManagerClientProtocol(transport, inputProtocol, outputProtocol)

		if err := transport.Open(); err != nil {
			log.Fatal("uds transport open error[userManager]:", err)
		}
		clientsPool <- userManagerClient
	}

	log.Print("start...")

	times := 100000

	ret := make(chan int, times)

	for i := 0; i < times; i++ {
		go func() {
			fromInfo := entity.NewFromInfo()
			fromInfo.Ctx = getUdsCtx()
			fromInfo.FromUid = 1000501
			fromInfo.FromIid = IID
			fromInfo.FromNjs = NJS

			userManagerClient := <-clientsPool
			//			_, err := userManagerClient.GetUserByPhone("15201218403")
			//			_, err := userManagerClient.GetUserById(1000501, entity.DBQueryStatus_NORMAL)
			err := userManagerClient.GetUserById(fromInfo.FromUid, fromInfo)
			clientsPool <- userManagerClient
			if err != nil {
				log.Fatal(err)
			}
			//			log.Print(u.GetBasic().Uid)
			ret <- 1
		}()
	}

	for i := 0; i < times; i++ {
		<-ret
	}

	log.Print("end...")

}