Coder Social home page Coder Social logo

trainking.github.io's Introduction

Hi! I'm xiaoye 👋

  • 🔭 I’m currently working on game company.
  • ⚡ Golang/Python/C/C++/C#.
  • 📫 How to reach me: [email protected]
  • 🍻 Guangzhou,China

trainking.github.io's People

Contributors

trainking avatar

Watchers

 avatar  avatar

trainking.github.io's Issues

【Mark】Arpc同一个client发起请求不异步

func main() {
	var client *arpc.Client
	var err error
	client, err = arpc.NewClient(dialer)
	if err != nil {
		log.Fatalf("NewClient failed: %v", err)
	}
	defer client.Stop()

	request := hello.Request{X: 10, Y: 20}

	str := ""
	client.CallAsync("/gg", &request, func(ctx *arpc.Context) {
		ctx.Bind(&str)
		log.Printf("Call /gg Response: %v", str)
	}, time.Second*3)

	// var pClient *arpc.Client
	// pClient, err = arpc.NewClient(dialer)
	// if err != nil {
	// 	log.Fatalf("NewClient failed: %v", err)
	// }
	response := hello.Response{}
	err = client.CallWith(context.Background(), "/echo", &request, &response)
	var rr map[string]interface{} = response.List[0].(map[string]interface{})
	if err != nil {
		log.Fatalf("Call /echo failed: %v", err)
	} else {
		log.Printf("Call /echo Response: %v", rr)
	}

	time.Sleep(time.Second * 10)
}

arpc中同一个*arpc.Clent使用callAsynccallWIth异步请求也会阻塞其他请求

因为,同一个*arpc.Client必须等待结果,他们内部调用的是同一个client.newRequestMessage函数,发送请求。不一样的是异步请求调用之后,进入等待结果,其他代码可以执行,但是在结果到来之前,这个*arpc.Client不能再发送其他请求。

因此,arpc最好使用一个请求新建client的方式,避免这种阻塞。

arpc的异步请求需要在服务端设置,才能作为真正的异步请求

        async := true
	handler.Handle("/gg", func(ctx *arpc.Context) {
		time.Sleep(time.Second * 10)
		ctx.Write("ppte")
	}, async)

【mark】redis的常规操作

访问远程服务,需要配置配置文件

#bind 127.0.0.1
bind 0.0.0.0

重启服务即可。

用命令查看是否生效:

> ps -ef  | grep redis
redis     5346     1  0 Dec19 ?        00:00:30 /usr/local/redis/bin/redis-serve                                                                               r 0.0.0.0:6379
root     16172 16062  0 09:12 pts/0    00:00:00 grep --color redis

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.