<?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>《重新封包的python smtplib》的评论</title>
	<atom:link href="http://www.litrin.net/2010/06/30/%e9%87%8d%e6%96%b0%e5%b0%81%e5%8c%85%e7%9a%84python-smtplib/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.litrin.net/2010/06/30/%e9%87%8d%e6%96%b0%e5%b0%81%e5%8c%85%e7%9a%84python-smtplib/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=%25e9%2587%258d%25e6%2596%25b0%25e5%25b0%2581%25e5%258c%2585%25e7%259a%2584python-smtplib</link>
	<description>It is Cool to OpenSource</description>
	<lastBuildDate>Fri, 03 Feb 2012 03:21:10 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>作者：说说Python的垃圾回收机制 &#171; 开源小站</title>
		<link>http://www.litrin.net/2010/06/30/%e9%87%8d%e6%96%b0%e5%b0%81%e5%8c%85%e7%9a%84python-smtplib/comment-page-1/#comment-1825</link>
		<dc:creator>说说Python的垃圾回收机制 &#171; 开源小站</dc:creator>
		<pubDate>Tue, 08 Feb 2011 05:27:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.litrin.net/?p=1269#comment-1825</guid>
		<description>[...] .recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;} /**/  It is Cool to OpenSource  alimama_pid=&quot;mm_10024007_111853_121868&quot;; alimama_titlecolor=&quot;0000FF&quot;; alimama_descolor =&quot;000000&quot;; alimama_bgcolor=&quot;FFFFFF&quot;; alimama_bordercolor=&quot;E6E6E6&quot;; alimama_linkcolor=&quot;008000&quot;; alimama_bottomcolor=&quot;FFFFFF&quot;; alimama_anglesize=&quot;0&quot;; alimama_bgpic=&quot;0&quot;; alimama_icon=&quot;0&quot;; alimama_sizecode=&quot;12&quot;; alimama_width=468; alimama_height=60; alimama_type=2;  LinuxUnixwww开源7788数据库应用硬件相关站长的blog网络和安全&#171; 重新认识下PHP的输出说说Python的垃圾回收机制google_ad_client = &quot;pub-9603680922905816&quot;; /* 250x250, 创建于 10-4-29 */ google_ad_slot = &quot;3814271827&quot;; google_ad_width = 250; google_ad_height = 250; 作为Java和python这类相对设计比较完善的解释型语言而言，总有很严密的垃圾回收机制用以防止资源被浪费甚至内存溢出之类的问题。起先我始终认为这会大大提升系统的性能，然而这次碰上了悖论。 刚过完春节，春节前，考虑到会有很多人发送贺卡，邮件系统的压力剧增。同时春节期间无人值守，没有办法人为干预很多。于是我打包了之前的一段python程序用来在节日期间发送大量的邮件贺卡。 初次测试的过程中，由于仅仅只是测试下性能如何，没有“特别规矩”没有关闭定义的类，于是代码大致如此： for mailBody in mailList:         mail = SendMail()         mail.MailServer[&#039;UserName&#039;] = username         mail.MailServer[&#039;Password&#039;] = password          mail.MailServer[&#039;Host&#039;] = host         mail.MailServer[&#039;port&#039;] = port         mail.SenderName = senderName         mail.Charset = &#039;UTF-8&#039;         mail.AddMeta(&#039;Precedence&#039;, &#039;bulk&#039;)         delFromDb(mailBody[3])           try :             mail.Send(From = smtpFrom,               Address = mailBody[0],               Subject = mailBody[1],               Body = mailBody[2])                        logging.info(&#039;Mail send to: &#039; + mailBody[0] + &quot; with subject is &quot; + mailBody[1] + &quot; By thread #&quot; + str(thread))         except:             logging.error(&#039;Error send to: &#039; + mailBody[0] + &quot; with subject is &quot; + mailBody[1] +&quot;By thread #&quot; + str(thread))初版测试了一下，每小时的发送量保守达到2w左右。已经达到了要求，可以正式部署。 考虑到了生产环境中的服务器负载很高，于是对python的代码提出了更高的要求，在上述代码的最后加上了一句： mail = None 结束发送循环以后立即释放 SendMail()这个类占据的资源。这是一个程序员都应该遵守的好习惯。部署好了以后，再次测试，每小时仅能发送不足7000。性能仅有之前的30%。 多次拉锯测试，只要加上那句mail=None，性能就会下降。所有的性能缺陷都指向了这句“好习惯”。没什么说的，直接在头部加上 import gc gc.disable() 加不加那句已经没有实质性的影响了。Python不同于Java的垃圾回收机制，Java机制是只有等到资源，特别是内存资源紧张的情况下才会执行垃圾回收机制。而Python则是忠实于C++系的逻辑，只要资源没有被引用就回自动被回收机制无情的回收。 在这个例子中，由于Sendmail的类相对比较复杂的操作，每次构建和解构的过程都需要花费较长时间。而且由于Sendmail是主循环，占用了大量的内存，每次垃圾的回收系统都会重新整理内存碎片，如果每次都为释放内存而手工解构的话性能反而会大大降低。分享到：人人网 &#160;开心网 &#160;腾讯微博 &#160;新浪微博 &#160;豆瓣分享 &#160;腾讯空间 &#160;百度搜藏 &#160;腾讯书签 &#160;若邻分享 &#160;google_ad_client = &quot;pub-9603680922905816&quot;; /* 468x60, 创建于 10-4-29 */ google_ad_slot = &quot;7106004412&quot;; google_ad_width = 468; google_ad_height = 60; Python, 硬件相关 google_ad_client = &quot;pub-9603680922905816&quot;; /* 468x15, 创建于 10-1-7 */ google_ad_slot = &quot;7135317085&quot;; google_ad_width = 468; google_ad_height = 15; [...]</description>
		<content:encoded><![CDATA[<p>[...] .recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;} /**/  It is Cool to OpenSource  alimama_pid=&quot;mm_10024007_111853_121868&quot;; alimama_titlecolor=&quot;0000FF&quot;; alimama_descolor =&quot;000000&quot;; alimama_bgcolor=&quot;FFFFFF&quot;; alimama_bordercolor=&quot;E6E6E6&quot;; alimama_linkcolor=&quot;008000&quot;; alimama_bottomcolor=&quot;FFFFFF&quot;; alimama_anglesize=&quot;0&quot;; alimama_bgpic=&quot;0&quot;; alimama_icon=&quot;0&quot;; alimama_sizecode=&quot;12&quot;; alimama_width=468; alimama_height=60; alimama_type=2;  LinuxUnixwww<a title="开源7788" href="http://www.litrin.net/category/7788/">开源7788</a>数据库应用硬件相关站长的blog网络和安全&laquo; 重新认识下PHP的输出说说<a title="Python" href="http://www.litrin.net/tag/python/">Python</a>的垃圾回收机制google_ad_client = &quot;pub-9603680922905816&quot;; /* 250&#215;250, 创建于 10-4-29 */ google_ad_slot = &quot;3814271827&quot;; google_ad_width = 250; google_ad_height = 250; 作为Java和python这类相对设计比较完善的解释型语言而言，总有很严密的垃圾回收机制用以防止资源被浪费甚至内存溢出之类的问题。起先我始终认为这会大大提升系统的性能，然而这次碰上了悖论。 刚过完春节，春节前，考虑到会有很多人发送贺卡，邮件系统的压力剧增。同时春节期间无人值守，没有办法人为干预很多。于是我打包了之前的一段python程序用来在节日期间发送大量的邮件贺卡。 初次测试的过程中，由于仅仅只是测试下性能如何，没有“特别规矩”没有关闭定义的类，于是代码大致如此： for mailBody in mailList:         mail = SendMail()         mail.MailServer[&#039;UserName&#039;] = username         mail.MailServer[&#039;Password&#039;] = password          mail.MailServer[&#039;Host&#039;] = host         mail.MailServer[&#039;port&#039;] = port         mail.SenderName = senderName         mail.Charset = &#039;UTF-8&#039;         mail.AddMeta(&#039;Precedence&#039;, &#039;bulk&#039;)         delFromDb(mailBody[3])           try :             mail.Send(From = smtpFrom,               Address = mailBody[0],               Subject = mailBody[1],               Body = mailBody[2])                        logging.info(&#039;<a title="Mail" href="http://www.litrin.net/tag/mail/">Mail</a> send to: &#039; + mailBody[0] + &quot; with subject is &quot; + mailBody[1] + &quot; By thread #&quot; + str(thread))         except:             logging.error(&#039;Error send to: &#039; + mailBody[0] + &quot; with subject is &quot; + mailBody[1] +&quot;By thread #&quot; + str(thread))初版测试了一下，每小时的发送量保守达到2w左右。已经达到了要求，可以正式部署。 考虑到了生产环境中的服务器负载很高，于是对python的代码提出了更高的要求，在上述代码的最后加上了一句： mail = None 结束发送循环以后立即释放 SendMail()这个类占据的资源。这是一个程序员都应该遵守的好习惯。部署好了以后，再次测试，每小时仅能发送不足7000。性能仅有之前的30%。 多次拉锯测试，只要加上那句mail=None，性能就会下降。所有的性能缺陷都指向了这句“好习惯”。没什么说的，直接在头部加上 import gc gc.disable() 加不加那句已经没有实质性的影响了。Python不同于Java的垃圾回收机制，Java机制是只有等到资源，特别是内存资源紧张的情况下才会执行垃圾回收机制。而Python则是忠实于C++系的逻辑，只要资源没有被引用就回自动被回收机制无情的回收。 在这个例子中，由于Sendmail的类相对比较复杂的操作，每次构建和解构的过程都需要花费较长时间。而且由于Sendmail是主循环，占用了大量的内存，每次垃圾的回收系统都会重新整理内存碎片，如果每次都为释放内存而手工解构的话性能反而会大大降低。分享到：人人网 &nbsp;开心网 &nbsp;腾讯微博 &nbsp;新浪微博 &nbsp;豆瓣分享 &nbsp;腾讯空间 &nbsp;百度搜藏 &nbsp;腾讯书签 &nbsp;若邻分享 &nbsp;google_ad_client = &quot;pub-9603680922905816&quot;; /* 468&#215;60, 创建于 10-4-29 */ google_ad_slot = &quot;7106004412&quot;; google_ad_width = 468; google_ad_height = 60; Python, 硬件相关 google_ad_client = &quot;pub-9603680922905816&quot;; /* 468&#215;15, 创建于 10-1-7 */ google_ad_slot = &quot;7135317085&quot;; google_ad_width = 468; google_ad_height = 15; [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>作者：小说阅读网</title>
		<link>http://www.litrin.net/2010/06/30/%e9%87%8d%e6%96%b0%e5%b0%81%e5%8c%85%e7%9a%84python-smtplib/comment-page-1/#comment-1750</link>
		<dc:creator>小说阅读网</dc:creator>
		<pubDate>Sun, 04 Jul 2010 15:10:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.litrin.net/?p=1269#comment-1750</guid>
		<description>模板不错啊，支持下！</description>
		<content:encoded><![CDATA[<p>模板不错啊，支持下！</p>
]]></content:encoded>
	</item>
</channel>
</rss>

