<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>《Go程序调试、分析与优化》的评论</title>
	<atom:link href="http://tonybai.com/2015/08/25/go-debugging-profiling-optimization/feed/" rel="self" type="application/rss+xml" />
	<link>https://tonybai.com/2015/08/25/go-debugging-profiling-optimization/</link>
	<description>一个程序员的心路历程</description>
	<lastBuildDate>Wed, 25 Mar 2026 09:21:20 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>作者：AlphaBaby</title>
		<link>https://tonybai.com/2015/08/25/go-debugging-profiling-optimization/#comment-7485</link>
		<dc:creator>AlphaBaby</dc:creator>
		<pubDate>Thu, 20 Aug 2020 10:45:51 +0000</pubDate>
		<guid isPermaLink="false">http://tonybai.com/?p=1804#comment-7485</guid>
		<description>在 go1.15 中step8的优化则是没有用的，反而增加了竞争</description>
		<content:encoded><![CDATA[<p>在 go1.15 中step8的优化则是没有用的，反而增加了竞争</p>
]]></content:encoded>
	</item>
	<item>
		<title>作者：bigwhite</title>
		<link>https://tonybai.com/2015/08/25/go-debugging-profiling-optimization/#comment-7199</link>
		<dc:creator>bigwhite</dc:creator>
		<pubDate>Mon, 07 May 2018 01:32:56 +0000</pubDate>
		<guid isPermaLink="false">http://tonybai.com/?p=1804#comment-7199</guid>
		<description>regexp.Regexp内部是有一个mutex的，因此是goroutine-safe的，但mutex在并发时存在一定的性能损耗。step8目的就是建立一个regexp.Regexp pool，这样多个goroutine按需获取，这样不用每收到一个连接就创建一个Regexp，sync.Pool中的对象是暂时性的，在两个GC周期之间未被get出去的object会被gc掉，但pool的确增加对象重用的几率，减少gc的负担，因此一定程度上减少内存分配，提升整体性能。</description>
		<content:encoded><![CDATA[<p>regexp.Regexp内部是有一个mutex的，因此是goroutine-safe的，但mutex在并发时存在一定的性能损耗。step8目的就是建立一个regexp.Regexp pool，这样多个goroutine按需获取，这样不用每收到一个连接就创建一个Regexp，sync.Pool中的对象是暂时性的，在两个GC周期之间未被get出去的object会被gc掉，但pool的确增加对象重用的几率，减少gc的负担，因此一定程度上减少内存分配，提升整体性能。</p>
]]></content:encoded>
	</item>
	<item>
		<title>作者：bigwhite</title>
		<link>https://tonybai.com/2015/08/25/go-debugging-profiling-optimization/#comment-7198</link>
		<dc:creator>bigwhite</dc:creator>
		<pubDate>Mon, 07 May 2018 01:06:56 +0000</pubDate>
		<guid isPermaLink="false">http://tonybai.com/?p=1804#comment-7198</guid>
		<description>无论是否是buffered channel，go test执行到TestHandleHi_Recorder时，只是直接调用了handleHi，而你在demo.go中写的teller() goroutine并没有启动啊。因此测试始终阻塞在那里了啊。应该是visitors这个channel上。</description>
		<content:encoded><![CDATA[<p>无论是否是buffered channel，go test执行到TestHandleHi_Recorder时，只是直接调用了handleHi，而你在demo.go中写的teller() goroutine并没有启动啊。因此测试始终阻塞在那里了啊。应该是visitors这个channel上。</p>
]]></content:encoded>
	</item>
	<item>
		<title>作者：small-pig</title>
		<link>https://tonybai.com/2015/08/25/go-debugging-profiling-optimization/#comment-7197</link>
		<dc:creator>small-pig</dc:creator>
		<pubDate>Sun, 06 May 2018 12:27:43 +0000</pubDate>
		<guid isPermaLink="false">http://tonybai.com/?p=1804#comment-7197</guid>
		<description>你好，
不太理解step 8 为什么会优化之前的做法[让正则仅编译一次]。
我浅显的理解,sync.Pool不是会不定时被gc掉么,如果被gc了的话,又要重新编译正则了。</description>
		<content:encoded><![CDATA[<p>你好，<br />
不太理解step 8 为什么会优化之前的做法[让正则仅编译一次]。<br />
我浅显的理解,sync.Pool不是会不定时被gc掉么,如果被gc了的话,又要重新编译正则了。</p>
]]></content:encoded>
	</item>
	<item>
		<title>作者：small-pig</title>
		<link>https://tonybai.com/2015/08/25/go-debugging-profiling-optimization/#comment-7196</link>
		<dc:creator>small-pig</dc:creator>
		<pubDate>Sun, 06 May 2018 11:44:33 +0000</pubDate>
		<guid isPermaLink="false">http://tonybai.com/?p=1804#comment-7196</guid>
		<description>不好意思
var    c  = make(chan struct{}, 1)
func handleVistors() {
	c &lt;- struct{}{}
	vistors++
	&lt;-c
}

我这样写,测试依旧不通过，依旧是timeout。不知道为什么。</description>
		<content:encoded><![CDATA[<p>不好意思<br />
var    c  = make(chan struct{}, 1)<br />
func handleVistors() {<br />
	c &lt;- struct{}{}<br />
	vistors++<br />
	&lt;-c<br />
}</p>
<p>我这样写,测试依旧不通过，依旧是timeout。不知道为什么。</p>
]]></content:encoded>
	</item>
	<item>
		<title>作者：small-pig</title>
		<link>https://tonybai.com/2015/08/25/go-debugging-profiling-optimization/#comment-7195</link>
		<dc:creator>small-pig</dc:creator>
		<pubDate>Sun, 06 May 2018 11:24:43 +0000</pubDate>
		<guid isPermaLink="false">http://tonybai.com/?p=1804#comment-7195</guid>
		<description>//go-debug-profile-optimization/step0/demo.go
package main

import (
	&quot;fmt&quot;
	&quot;log&quot;
	&quot;net/http&quot;
	&quot;regexp&quot;
)

// must be accessed atomically

var add = make(chan struct{})
var total = make(chan int)

func getVistors() int {
	return &lt;-total
}

func addVistors() {
	add &lt;- struct{}{}
}

func teller() {
	var visitors int
	for {
		select {
		case &lt;-add:
			visitors += 1
		case total &lt;- visitors:
		}
	}
}

func handleHi(w http.ResponseWriter, r *http.Request) {
	if match, _ := regexp.MatchString(`^\w*$`, r.FormValue(&quot;color&quot;)); !match {
		http.Error(w, &quot;Optional color is invalid&quot;, http.StatusBadRequest)
		return
	}
	addVistors()
	visitNum := getVistors()
	w.Header().Set(&quot;Content-Type&quot;, &quot;text/html; charset=utf-8&quot;)
	w.Write([]byte(&quot;Welcome!You are visitor number &quot; + fmt.Sprint(visitNum) + &quot;!&quot;))
}
func main() {
	log.Printf(&quot;Starting on port 8080&quot;)
	go teller()
	http.HandleFunc(&quot;/hi&quot;, handleHi)
	log.Fatal(http.ListenAndServe(&quot;127.0.0.1:8080&quot;, nil))
}

请问big white大大,我使用了channel,为什么go test的时候会不成功?
现象是go test  timeout。</description>
		<content:encoded><![CDATA[<p>//go-debug-profile-optimization/step0/demo.go<br />
package main</p>
<p>import (<br />
	“fmt”<br />
	“log”<br />
	“net/http”<br />
	“regexp”<br />
)</p>
<p>// must be accessed atomically</p>
<p>var add = make(chan struct{})<br />
var total = make(chan int)</p>
<p>func getVistors() int {<br />
	return &lt;-total<br />
}</p>
<p>func addVistors() {<br />
	add &lt;- struct{}{}<br />
}</p>
<p>func teller() {<br />
	var visitors int<br />
	for {<br />
		select {<br />
		case &lt;-add:<br />
			visitors += 1<br />
		case total &lt;- visitors:<br />
		}<br />
	}<br />
}</p>
<p>func handleHi(w http.ResponseWriter, r *http.Request) {<br />
	if match, _ := regexp.MatchString(`^\w*$`, r.FormValue(&quot;color&quot;)); !match {<br />
		http.Error(w, &quot;Optional color is invalid&quot;, http.StatusBadRequest)<br />
		return<br />
	}<br />
	addVistors()<br />
	visitNum := getVistors()<br />
	w.Header().Set(&quot;Content-Type&quot;, &quot;text/html; charset=utf-8&quot;)<br />
	w.Write([]byte(&quot;Welcome!You are visitor number ” + fmt.Sprint(visitNum) + “!”))<br />
}<br />
func main() {<br />
	log.Printf(“Starting on port 8080&#8243;)<br />
	go teller()<br />
	http.HandleFunc(“/hi”, handleHi)<br />
	log.Fatal(http.ListenAndServe(“127.0.0.1:8080&#8243;, nil))<br />
}</p>
<p>请问big white大大,我使用了channel,为什么go test的时候会不成功?<br />
现象是go test  timeout。</p>
]]></content:encoded>
	</item>
	<item>
		<title>作者：Fred</title>
		<link>https://tonybai.com/2015/08/25/go-debugging-profiling-optimization/#comment-1717</link>
		<dc:creator>Fred</dc:creator>
		<pubDate>Tue, 06 Dec 2016 09:53:04 +0000</pubDate>
		<guid isPermaLink="false">http://tonybai.com/?p=1804#comment-1717</guid>
		<description>写的很不错，其中有个问题指出，以免后看者在测试验证时浪费不必要的时间使用pprof工具分析mem：$ go tool pprof –alloc_space step3.test prof.memEntering interactive mode (type &quot;help&quot; for commands)—中划线大写了–alloc_space（错误）-alloc_space</description>
		<content:encoded><![CDATA[<p>写的很不错，其中有个问题指出，以免后看者在测试验证时浪费不必要的时间使用pprof工具分析mem：$ go tool pprof –alloc_space step3.test prof.memEntering interactive mode (type “help” for commands)—中划线大写了–alloc_space（错误）-alloc_space</p>
]]></content:encoded>
	</item>
	<item>
		<title>作者：bigwhite</title>
		<link>https://tonybai.com/2015/08/25/go-debugging-profiling-optimization/#comment-1278</link>
		<dc:creator>bigwhite</dc:creator>
		<pubDate>Sat, 09 Jan 2016 12:45:29 +0000</pubDate>
		<guid isPermaLink="false">http://tonybai.com/?p=1804#comment-1278</guid>
		<description>我手头没有windows go开发环境，工作中也不用windows，您自己不妨摸索一下，有结论后，别忘了在这里的评论中补上一句。呵呵。</description>
		<content:encoded><![CDATA[<p>我手头没有windows go开发环境，工作中也不用windows，您自己不妨摸索一下，有结论后，别忘了在这里的评论中补上一句。呵呵。</p>
]]></content:encoded>
	</item>
	<item>
		<title>作者：8094731</title>
		<link>https://tonybai.com/2015/08/25/go-debugging-profiling-optimization/#comment-1277</link>
		<dc:creator>8094731</dc:creator>
		<pubDate>Sat, 09 Jan 2016 06:06:10 +0000</pubDate>
		<guid isPermaLink="false">http://tonybai.com/?p=1804#comment-1277</guid>
		<description>在windows 7中，为什么我执行后的没有*.test文件  其他的都好。</description>
		<content:encoded><![CDATA[<p>在windows 7中，为什么我执行后的没有*.test文件  其他的都好。</p>
]]></content:encoded>
	</item>
	<item>
		<title>作者：Hessian海生</title>
		<link>https://tonybai.com/2015/08/25/go-debugging-profiling-optimization/#comment-1172</link>
		<dc:creator>Hessian海生</dc:creator>
		<pubDate>Sat, 10 Oct 2015 02:46:35 +0000</pubDate>
		<guid isPermaLink="false">http://tonybai.com/?p=1804#comment-1172</guid>
		<description>找个代码高亮插件吧</description>
		<content:encoded><![CDATA[<p>找个代码高亮插件吧</p>
]]></content:encoded>
	</item>
</channel>
</rss>
