question on writing an RPC server in golang.

agolangf · · 421 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I&#39;m trying to split an application into specific server processes behind a message broker. ATM, I&#39;m working on the register server that will run an http RPC in golang. my question is from the example code I see here <a href="https://golang.org/pkg/net/rpc/" rel="nofollow">link</a>. Assuming I&#39;m using go-sql-driver, would it be okay to just open a new db driver for each request?</p> <hr/>**评论:**<br/><br/>albatr0s: <pre><p>According to the documentation: <em>The returned DB is safe for concurrent use by multiple goroutines and maintains its own pool of idle connections. Thus, the Open function should be called just once. It is rarely necessary to close a DB.</em></p></pre>kubuni: <pre><p>Yeah, I was looking for suggestions on how to implement a global with the db variable. I found this off <a href="https://stackoverflow.com/questions/31218008/sharing-a-globally-defined-db-conn-with-multiple-packages-in-golang" rel="nofollow">stackoverflow solution</a></p></pre>lhxtx: <pre><p>The db connection maintains a connection pool. Opening a new connection on every request is no bueno. </p> <p>Also look into gRPC. It’s blazing fast. </p></pre>kubuni: <pre><p>I looked into the pros of gRPC; it&#39;s a nice library I&#39;ll probably use in the future. lol looks like it has a steep learning curve.</p></pre>chris-sotherden: <pre><p>Learning gRPC looks more daunting than it actually is. You spend a little time learning protobufs and then you compile it into the generated Go code and you&#39;re off and running. Once you&#39;re familiar with protobufs you&#39;ll be able to go from zero to implementing your business logic in minutes. There&#39;s a few gems in the protobuf spec that once you&#39;re aware of them really help simplify your RPC interface, like &#34;one of&#34;.</p></pre>lhxtx: <pre><p>It’s a lot easier in practice once you learn how to write the proto file and call the generation script. </p></pre>dark_magician2: <pre><p>gRPC</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

421 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传