<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title> &#187; golang</title>
	<atom:link href="http://www.liguosong.com/tag/golang/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.liguosong.com</link>
	<description></description>
	<lastBuildDate>Tue, 08 May 2018 01:02:19 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.2</generator>
		<item>
		<title>go 服务器出现too many open files的错误</title>
		<link>http://www.liguosong.com/2014/01/15/go-%e6%9c%8d%e5%8a%a1%e5%99%a8%e5%87%ba%e7%8e%b0too-many-open-files%e7%9a%84%e9%94%99%e8%af%af/</link>
		<comments>http://www.liguosong.com/2014/01/15/go-%e6%9c%8d%e5%8a%a1%e5%99%a8%e5%87%ba%e7%8e%b0too-many-open-files%e7%9a%84%e9%94%99%e8%af%af/#comments</comments>
		<pubDate>Tue, 14 Jan 2014 23:41:19 +0000</pubDate>
		<dc:creator>lgs</dc:creator>
				<category><![CDATA[golang]]></category>
		<category><![CDATA[too many open files]]></category>

		<guid isPermaLink="false">http://www.liguosong.com/?p=241</guid>
		<description><![CDATA[最近两天服务器总是会出现too many open files的错误。真的很是头疼。在本地开发环境中，也用了压 [...]]]></description>
				<content:encoded><![CDATA[<p>最近两天服务器总是会出现too many open files的错误。真的很是头疼。在本地开发环境中，也用了压力测试，发现问题不存在。但是为什么服务器会出现这种错误，有些闹不明白。本来想用ulimit更改一下打开文件的描述符。但这样子觉得并不解决问题。好吧，那就查一下更本的原因。<span id="more-241"></span></p>
<p>服务器是亚马逊，开发语言：golang，数据库：mongo，mysql。缓存：redis。</p>
<p>测试脚本：写了一个golang的并发请求脚本。大概同时请求100.ulimit限制到50.发现错误立刻呈现。发现在程序的进程下打开了大量的socket连接。所以当时就认为是mongo的连接错误。决定mongo的连接使用单例模式。不过后来发现，这些socket是会降下去的。也就是说，连接用完了，就关闭了。但是服务器的socket连接已经明显超过了ulimit的默认限制。项目也刚刚上线，也没有这么大的用户群。所以问题肯定不是处在了mongo的连接错误上。那是redis，mysql?后经过测试，也并不是这些连接的错误。</p>
<p>整的真是很晕啊。最后想起来了，可以看一下服务器的socket的连接是哪些请求。经过查看，发现是80端口。一个网站的。。搞了一天，方向错了。。。突然想起来了，最近添加的一个小功能，需要使用外网的api。在go打开连接后，好像没有关闭请求。加上关闭请求后，问题解决。socket上去，然后会自动下来。</p>
<p>总结：以后要及时关闭这些请求连接。go与php不一样。php在执行完成后，即使你不关闭请求，在解析完成后，所以变量，都会自动释放。go是编译行语言，所以连接打开后，如果不手动关闭，会一直占用。。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.liguosong.com/2014/01/15/go-%e6%9c%8d%e5%8a%a1%e5%99%a8%e5%87%ba%e7%8e%b0too-many-open-files%e7%9a%84%e9%94%99%e8%af%af/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>golang goroutine</title>
		<link>http://www.liguosong.com/2013/09/13/golang-goroutine/</link>
		<comments>http://www.liguosong.com/2013/09/13/golang-goroutine/#comments</comments>
		<pubDate>Fri, 13 Sep 2013 15:59:53 +0000</pubDate>
		<dc:creator>lgs</dc:creator>
				<category><![CDATA[golang]]></category>

		<guid isPermaLink="false">http://www.liguosong.com/?p=189</guid>
		<description><![CDATA[golang中有一个功能，我非常喜欢，就是goroutine。这个是go里面起子线程的一个功能。这个据说一个g [...]]]></description>
				<content:encoded><![CDATA[<p>golang中有一个功能，我非常喜欢，就是goroutine。这个是go里面起子线程的一个功能。这个据说一个goroutine才几KB，这个真的很小，看起来真的很不错。不过我发现在使用的过程中，如果一个子线程崩溃了，直接导致了主线程的崩溃。看来在每一个子线程中，都需要进行recover的错误捕捉。要不然编译器完了，老板会疯掉的。。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.liguosong.com/2013/09/13/golang-goroutine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
