[Help]New to GO, how easy is it to do synchronus http requests?

xuanbao · · 149 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Python is pain to do this in...is it possible to do a lot of http requests easily in GO? With something similar to multiprocessing in GO?</p> <hr/>**评论:**<br/><br/>lolis5: <pre><p>Short answer is &#34;very yes&#34;. The core net/http library uses goroutines for request handling, which allows for handling multiple requests simultaneously.</p> <p>Multiprocessing, at least as you know it in python, isn&#39;t really a thing in go, but that&#39;s because it would introduce unnecessary overhead.</p> <p>In Python, (cpython specifically) multi-threading is not very useful in most cases because only one thread may be running interpreted python code at a time because of a global interpreter lock. Python gets around this bottleneck by introducing multiple processes, each with its own interpreter lock. </p> <p>In go, there is no equivalent concept. Goroutines can take full advantage of multiple processors and the language itself is responsible for scheduling them. They are similar to os threads in concept, but are much lighter weight.(Almost identical to the concept of fibers on Windows).</p> <p>Hope this helps. </p></pre>Redundancy_: <pre><p>It&#39;s worth going through the tour of Go. Concurrency part 10 Exercise covers a webcrawler that does concurrent http requests: <a href="https://tour.golang.org/concurrency/10" rel="nofollow">https://tour.golang.org/concurrency/10</a></p> <p>Also: <a href="http://blog.narenarya.in/concurrent-http-in-go.html" rel="nofollow">http://blog.narenarya.in/concurrent-http-in-go.html</a> <a href="https://matt.aimonetti.net/posts/2012/11/27/real-life-concurrency-in-go/" rel="nofollow">https://matt.aimonetti.net/posts/2012/11/27/real-life-concurrency-in-go/</a></p></pre>tmornini: <pre><p>Synchronous is easy, and slow, in every language.</p> <p>What you&#39;re looking for is asynchronous.</p> <p>Go excels at asynchronous workloads.</p> <p>Take a look at goroutines and channels.</p></pre>

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

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