<?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>泛城科技技术博客</title>
	<atom:link href="http://tech.lezi.com/feed" rel="self" type="application/rss+xml" />
	<link>http://tech.lezi.com</link>
	<description></description>
	<lastBuildDate>Fri, 04 Jan 2013 09:18:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>C++ Boost智能指针小测</title>
		<link>http://tech.lezi.com/archives/392</link>
		<comments>http://tech.lezi.com/archives/392#comments</comments>
		<pubDate>Tue, 24 Apr 2012 06:30:21 +0000</pubDate>
		<dc:creator>neilxp</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[c++]]></category>

		<guid isPermaLink="false">http://tech.lezi.com/?p=392</guid>
		<description><![CDATA[请阅读该文档(http://www.boost.org/doc/libs/1_49_0/libs/smart_ptr/shared_ptr.htm)，回答以下问题： boost::shared_ptr能存放数组指针吗？如果不能，应该使用什么？ 与std::auto_ptr相比，boost::shared_ptr有什么优势？ 对于一般指针的dynamic_cast，boost::shared_ptr应该怎么cast？ 什么情况下使用shared_from_this? 如何获取shared_ptr中保存的具体对象的指针？ 如果要释放某shared_ptr对指针的引用，应该怎么操作？ 什么情况使用weak_ptr? shared_ptr怎么管理file, MYSQL_RES, CURL等资源？ 您也许会对以下文章感兴趣 C++程序注意事项 (评论：4) c++版本的普通程序员,文艺程序员,2b程序员和失足程序员 (评论：1)]]></description>
			<content:encoded><![CDATA[<p>请阅读该文档(<a href="http://www.boost.org/doc/libs/1_49_0/libs/smart_ptr/shared_ptr.htm">http://www.boost.org/doc/libs/1_49_0/libs/smart_ptr/shared_ptr.htm</a>)，回答以下问题：</p>
<ol>
<li>boost::shared_ptr能存放数组指针吗？如果不能，应该使用什么？</li>
<li>与std::auto_ptr相比，boost::shared_ptr有什么优势？</li>
<li>对于一般指针的dynamic_cast，boost::shared_ptr应该怎么cast？</li>
<li>什么情况下使用shared_from_this?</li>
<li>如何获取shared_ptr中保存的具体对象的指针？</li>
<li>如果要释放某shared_ptr对指针的引用，应该怎么操作？</li>
<li>什么情况使用weak_ptr?</li>
<li>shared_ptr怎么管理file, MYSQL_RES, CURL等资源？</li>
</ol>

	<h2>您也许会对以下文章感兴趣</h2>
	<ul class="st-related-posts">
	<li><a href="http://tech.lezi.com/archives/379" title="C++程序注意事项 (四月 5, 2012)">C++程序注意事项</a> (评论：4)</li>
	<li><a href="http://tech.lezi.com/archives/329" title="c++版本的普通程序员,文艺程序员,2b程序员和失足程序员 (十一月 12, 2011)">c++版本的普通程序员,文艺程序员,2b程序员和失足程序员</a> (评论：1)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://tech.lezi.com/archives/392/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>C++程序注意事项</title>
		<link>http://tech.lezi.com/archives/379</link>
		<comments>http://tech.lezi.com/archives/379#comments</comments>
		<pubDate>Thu, 05 Apr 2012 03:23:52 +0000</pubDate>
		<dc:creator>neilxp</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[c++]]></category>

		<guid isPermaLink="false">http://tech.lezi.com/?p=379</guid>
		<description><![CDATA[智能指针 为了避免 遗忘释放内存、资源 中途return，需要多处调用释放内存，资源 放到容器中的指针，错误释放内存，资源 我们写c++程序时，都使用智能指针来帮助管理内存和资源。c++不是c，提供的便捷要利用起来： 不使用任何明确的delete语句 熟悉并熟练使用 std::auto_ptr, boost::shared_ptr, boost::shared_array, boost::scoped_ptr, boost::scoped_array Don&#8217;t 动态分配内存，不要使用以下方法. 因为 1 处会抛出异常造成delete无法释放。 int n = 100; char *p = new char[n]; ....// 1: 使用p delete []p; Do 使用以下任一方法分配、管理内存 int n = 100; std::vector v; v.resize(n); ....// 使用 &#38;v.at(0)或者&#38;v[0], 与上面的p等价 // 不需要调用delete[] 或者 int n = 100; boost::shared_array p(new char[n]); [...]]]></description>
			<content:encoded><![CDATA[<h1>智能指针</h1>
<p>为了避免</p>
<ol>
<li>遗忘释放内存、资源</li>
<li>中途return，需要多处调用释放内存，资源</li>
<li>放到容器中的指针，错误释放内存，资源</li>
</ol>
<p>我们写c++程序时，都使用智能指针来帮助管理内存和资源。c++不是c，提供的便捷要利用起来：</p>
<h2>不使用任何明确的delete语句</h2>
<p>熟悉并熟练使用 std::auto_ptr, boost::shared_ptr, boost::shared_array, boost::scoped_ptr, boost::scoped_array</p>
<h3>Don&#8217;t</h3>
<p>动态分配内存，<strong>不要</strong>使用以下方法. 因为 1 处会抛出异常造成delete无法释放。</p>
<pre class="brush:cpp">int n = 100;
char *p = new char[n];
....// 1: 使用p
delete []p;</pre>
<h3>Do</h3>
<p>使用以下任一方法分配、管理内存</p>
<pre class="brush:cpp">int n = 100;
std::vector v;
v.resize(n);
....// 使用 &amp;v.at(0)或者&amp;v[0], 与上面的p等价
// 不需要调用delete[]</pre>
<p>或者</p>
<pre class="brush:cpp">int n = 100;
boost::shared_array p(new char[n]); // 或者使用boost::scoped_array
// 不需要调用delete[]</pre>
<h2>不要直接调用系统锁资源和解锁资源</h2>
<p>使用以下方法管理mutex</p>
<pre class="brush:cpp">void foo(const char* fileName)
{
  boost::unique_lock lock(gMutex);
  // 竞争区域的代码
  return;
}</pre>
<h2>不要直接调用close, fclose, mysql_close, mysql_free_result, curl_easy_cleanup这些方关闭文件、数据库等资源的方法</h2>
<h3>Don&#8217;t</h3>
<p>打开文件，关闭文件，<strong>不要</strong>使用以下方法. 因为 2 处会抛出异常造成fclose无法释放。</p>
<pre class="brush:cpp">FILE *file = fopen(filename, "rb");
// 2, 使用 file
fclose(file);</pre>
<h3>Do</h3>
<p>使用以下方法管理文件指针</p>
<pre class="brush:cpp">struct CFileCloser{
  void operator ()(FILE* file){
    if (file) fclose(file);
  }
};

void foo(const char* fileName)
{
  boost::shared_ptr backgroundFile(fopen(fileName, "rb"), CFileCloser());
}</pre>
<p>使用以下方法管理MYSQL_RES</p>
<pre class="brush:cpp">boost::shared_ptr
    resultSp(mysql_store_result(&amp;mysql_), mysql_free_result);

if (!resultSp) {
    LOG4CXX_ERROR(gLogger, "error in mysql connection: " &lt;&lt; mysql_error(&amp;mysql_));
    return false;
}

boost::uint64_t numRows = mysql_num_rows(resultSp.get());
MYSQL_ROW row = mysql_fetch_row(resultSp.get());</pre>
<p>使用以下方法管理CURL</p>
<pre class="brush:cpp">bool performUrl(const std::string url, std::string&amp; result)
{
        std::stringstream oss;

        CURL* curl = curl_easy_init();
        boost::shared_ptr  pointer(curl, curl_easy_cleanup);
        if(curl)
        {
                curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
                curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
                curl_easy_setopt(curl, CURLOPT_TIMEOUT, 1);
                curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeData);
                curl_easy_setopt(curl, CURLOPT_WRITEDATA, &amp;oss);
                curl_easy_perform(curl);

                result = oss.str();
                return true;
        }
        return false;
}</pre>
<h1>换掉一些可能造成crash的不安全函数</h1>
<p>使用std::ostringstream或者snprintf代替sprintf</p>
<pre class="brush:cpp">
  std::ostringstream oss;
  oss << DaemonConfig::disconnectNotifyURL << "?id=" << playerId;
</pre>

	<h2>您也许会对以下文章感兴趣</h2>
	<ul class="st-related-posts">
	<li><a href="http://tech.lezi.com/archives/329" title="c++版本的普通程序员,文艺程序员,2b程序员和失足程序员 (十一月 12, 2011)">c++版本的普通程序员,文艺程序员,2b程序员和失足程序员</a> (评论：1)</li>
	<li><a href="http://tech.lezi.com/archives/392" title="C++ Boost智能指针小测 (四月 24, 2012)">C++ Boost智能指针小测</a> (评论：1)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://tech.lezi.com/archives/379/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>CSDN 600万用户密码泄露事件受害者查询</title>
		<link>http://tech.lezi.com/archives/372</link>
		<comments>http://tech.lezi.com/archives/372#comments</comments>
		<pubDate>Wed, 21 Dec 2011 14:27:01 +0000</pubDate>
		<dc:creator>neilxp</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://tech.lezi.com/?p=372</guid>
		<description><![CDATA[CSDN 600万用户密码泄露事件受害者查询 泄露么 如果查询结果有你的密码，请尽快修使用这个密码的所有账户的密码，包括你的263邮箱，GMail, 支付宝，淘宝等. 您也许会对以下文章感兴趣 No related posts.]]></description>
			<content:encoded><![CDATA[<div>CSDN 600万用户密码泄露事件受害者查询 <a href="http://xielou.me" target="_blank">泄露么</a></div>
<div>如果查询结果有你的密码，请尽快修使用这个密码的所有账户的密码，包括你的263邮箱，GMail, 支付宝，淘宝等.</div>
<div><a href="http://tech.lezi.com/wp-content/uploads/2011/12/CSDN-60万用户密码泄露rar事件受害者查询-1.jpg"><img class="alignnone size-full wp-image-373" title="CSDN 60万用户密码泄露rar事件受害者查询-1" src="http://tech.lezi.com/wp-content/uploads/2011/12/CSDN-60万用户密码泄露rar事件受害者查询-1.jpg" alt="" width="1017" height="364" /></a></div>

	<h2>您也许会对以下文章感兴趣</h2>
	<ul class="st-related-posts">
	<li>No related posts.</li>
	</ul>

]]></content:encoded>
			<wfw:commentRss>http://tech.lezi.com/archives/372/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>一个不错的NodeJS教程</title>
		<link>http://tech.lezi.com/archives/353</link>
		<comments>http://tech.lezi.com/archives/353#comments</comments>
		<pubDate>Fri, 18 Nov 2011 10:31:43 +0000</pubDate>
		<dc:creator>neilxp</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[NodeJS]]></category>

		<guid isPermaLink="false">http://tech.lezi.com/?p=353</guid>
		<description><![CDATA[介绍了NodeJS的历史,优势劣势, 安装,使用方法 Server-Side JavaScript Developement &#8211; Node.JS Quick Tour 您也许会对以下文章感兴趣 No related posts.]]></description>
			<content:encoded><![CDATA[<p>介绍了NodeJS的历史,优势劣势, 安装,使用方法</p>
<div id="__ss_6212200" style="width: 425px;"><strong style="display: block; margin: 12px 0 4px;"></strong></div>
<div style="width: 425px;"><strong style="display: block; margin: 12px 0 4px;"></strong></div>
<div style="width: 425px;"><strong style="display: block; margin: 12px 0 4px;"><a title="Server-Side JavaScript Developement - Node.JS Quick Tour" href="http://www.slideshare.net/q3boy/serverside-javascript-developement-nodejs-quick-tour-6212200" target="_blank">Server-Side JavaScript Developement &#8211; Node.JS Quick Tour</a></strong> <iframe src="http://www.slideshare.net/slideshow/embed_code/6212200" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" width="425" height="355"></iframe></div>

	<h2>您也许会对以下文章感兴趣</h2>
	<ul class="st-related-posts">
	<li>No related posts.</li>
	</ul>

]]></content:encoded>
			<wfw:commentRss>http://tech.lezi.com/archives/353/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>c++版本的普通程序员,文艺程序员,2b程序员和失足程序员</title>
		<link>http://tech.lezi.com/archives/329</link>
		<comments>http://tech.lezi.com/archives/329#comments</comments>
		<pubDate>Sat, 12 Nov 2011 04:42:38 +0000</pubDate>
		<dc:creator>neilxp</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[c++]]></category>

		<guid isPermaLink="false">http://tech.lezi.com/?p=329</guid>
		<description><![CDATA[逆序输出字符串 普通程序员 #include &#60;iostream&#62; using namespace std; char *str = "n!dlrow olleh"; int main (int argc, char** argv) { for(char *p = str + strlen(str); p &#62;= str; p--){ cout &#60;&#60; *p; } return 0; } 文艺程序员 #include &#60;iostream&#62; #include &#60;iterator&#62; #include &#60;algorithm&#62; using namespace std; static char *str = "n!dlrow olleh"; int main (int [...]]]></description>
			<content:encoded><![CDATA[<p>逆序输出字符串</p>
<p>普通程序员</p>
<pre class="brush:c">#include &lt;iostream&gt;
using namespace std;
char *str = "n!dlrow olleh";

int main (int argc, char** argv) {
  for(char *p = str + strlen(str); p &gt;= str; p--){
    cout &lt;&lt; *p;
  }
  return 0;
}</pre>
<p>文艺程序员</p>
<pre class="brush:c">#include &lt;iostream&gt;
#include &lt;iterator&gt;
#include &lt;algorithm&gt;

using namespace std;

static char *str = "n!dlrow olleh";

int main (int argc, char** argv) {
  reverse_copy(str, str + strlen(str) + 1, 
    ostream_iterator&lt;char&gt;(cout, ""));
  return EXIT_SUCCESS;
}</pre>
<p>2B程序员</p>
<pre class="brush:c">#include &lt;iostream.h&gt;

static char *str = "n!dlrow olleh";

int main () {
  char *p = str + strlen(str);
  putchar(*(p--));
  putchar(*(p--));
  putchar(*(p--));
  putchar(*(p--));
  putchar(*(p--));
  putchar(*(p--));
  putchar(*(p--));
  putchar(*(p--));
  putchar(*(p--));
  putchar(*(p--));
  putchar(*(p--));
  putchar(*(p--));
  putchar(*(p--));
  putchar(*(p--));
}</pre>
<p>失足程序员</p>
<pre class="brush:c">#include &lt;iostream&gt;
using namespace std;

const char str[] = "n!dlrow olleh";

template&lt; int N &gt;
struct Printer{
    void operator()(){
        cout &lt;&lt; *(str + N);
    }
};

template&lt; template &lt; int &gt; class C, int N &gt;
struct Rev{
    Rev(){
        C&lt; N &gt;()();
        Rev&lt; C, N - 1&gt;();
    }
};

template&lt; template &lt; int &gt; class C &gt;
struct Rev&lt;C, 0&gt;{
    Rev(){
        C&lt; 0 &gt;()();
    }
};

template &lt;int N&gt;
int len_trait(const char (&amp;)[N])
{
    static Rev&lt; Printer, N &gt; rev;
    return 0;
}

static int dummy = len_trait(str);

int main(int argc, char** argv)
{
    return EXIT_SUCCESS;
}</pre>

	<h2>您也许会对以下文章感兴趣</h2>
	<ul class="st-related-posts">
	<li><a href="http://tech.lezi.com/archives/379" title="C++程序注意事项 (四月 5, 2012)">C++程序注意事项</a> (评论：4)</li>
	<li><a href="http://tech.lezi.com/archives/392" title="C++ Boost智能指针小测 (四月 24, 2012)">C++ Boost智能指针小测</a> (评论：1)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://tech.lezi.com/archives/329/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MongoDB运行状态、性能监控，分析</title>
		<link>http://tech.lezi.com/archives/290</link>
		<comments>http://tech.lezi.com/archives/290#comments</comments>
		<pubDate>Wed, 26 Oct 2011 14:53:47 +0000</pubDate>
		<dc:creator>neilxp</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[mongodb]]></category>

		<guid isPermaLink="false">http://tech.lezi.com/?p=290</guid>
		<description><![CDATA[这篇文章的目的是让你知道怎么了解你正在运行的Mongdb是否健康。 mongostat详解 mongostat是mongdb自带的状态检测工具，在命令行下使用。它会间隔固定时间获取mongodb的当前运行状态，并输出。如果你发现数据库突然变慢或者有其他问题的话，你第一手的操作就考虑采用mongostat来查看mongo的状态。 它的输出有以下几列： inserts/s 每秒插入次数 query/s 每秒查询次数 update/s 每秒更新次数 delete/s 每秒删除次数 getmore/s 每秒执行getmore次数 command/s 每秒的命令数，比以上插入、查找、更新、删除的综合还多，还统计了别的命令 flushs/s 每秒执行fsync将数据写入硬盘的次数。 mapped/s 所有的被mmap的数据量，单位是MB， vsize 虚拟内存使用量，单位MB res 物理内存使用量，单位MB faults/s 每秒访问失败数（只有Linux有），数据被交换出物理内存，放到swap。不要超过100，否则就是机器内存太小，造成频繁swap写入。此时要升级内存或者扩展 locked % 被锁的时间百分比，尽量控制在50%以下吧 idx miss % 索引不命中所占百分比。如果太高的话就要考虑索引是不是少了 q t&#124;r&#124;w 当Mongodb接收到太多的命令而数据库被锁住无法执行完成，它会将命令加入队列。这一栏显示了总共、读、写3个队列的长度，都为0的话表示mongo毫无压力。高并发时，一般队列值会升高。 conn 当前连接数 time 时间戳 使用profiler 类似于MySQL的slow log, MongoDB可以监控所有慢的以及不慢的查询。 Profiler默认是关闭的，你可以选择全部开启，或者有慢查询的时候开启。 &#62; use test switched to db test &#62; db.setProfilingLevel(2); {"was" [...]]]></description>
			<content:encoded><![CDATA[<p>这篇文章的目的是让你知道怎么了解你正在运行的Mongdb是否健康。<br />
<span id="more-290"></span></p>
<h1>mongostat详解</h1>
<p><a href="http://tech.lezi.com/wp-content/uploads/2011/10/mongod_stat.png"><img class="alignright size-medium wp-image-315" title="mongod_stat" src="http://tech.lezi.com/wp-content/uploads/2011/10/mongod_stat-300x46.png" alt="mongo stat" width="300" height="46" /></a>mongostat是mongdb自带的状态检测工具，在命令行下使用。它会间隔固定时间获取mongodb的当前运行状态，并输出。如果你发现数据库突然变慢或者有其他问题的话，你第一手的操作就考虑采用mongostat来查看mongo的状态。</p>
<p>它的输出有以下几列：</p>
<ul>
<li>inserts/s 每秒插入次数</li>
<li>query/s 每秒查询次数</li>
<li>update/s 每秒更新次数</li>
<li>delete/s 每秒删除次数</li>
<li>getmore/s 每秒执行getmore次数</li>
<li>command/s 每秒的命令数，比以上插入、查找、更新、删除的综合还多，还统计了别的命令</li>
<li>flushs/s 每秒执行fsync将数据写入硬盘的次数。</li>
<li>mapped/s 所有的被mmap的数据量，单位是MB，</li>
<li>vsize 虚拟内存使用量，单位MB</li>
<li>res 物理内存使用量，单位MB</li>
<li>faults/s 每秒访问失败数（只有Linux有），数据被交换出物理内存，放到swap。不要超过100，否则就是机器内存太小，造成频繁swap写入。此时要升级内存或者扩展</li>
<li>locked % 被锁的时间百分比，尽量控制在50%以下吧</li>
<li>idx miss % 索引不命中所占百分比。如果太高的话就要考虑索引是不是少了</li>
<li>q t|r|w 当Mongodb接收到太多的命令而数据库被锁住无法执行完成，它会将命令加入队列。这一栏显示了总共、读、写3个队列的长度，都为0的话表示mongo毫无压力。高并发时，一般队列值会升高。</li>
<li>conn 当前连接数</li>
<li>time 时间戳</li>
</ul>
<h1>使用profiler</h1>
<p><a href="http://tech.lezi.com/wp-content/uploads/2011/10/mongo_profile.png"><img class="alignright size-medium wp-image-313" title="mongo_profile" src="http://tech.lezi.com/wp-content/uploads/2011/10/mongo_profile-300x131.png" alt="Mongo profile" width="300" height="131" /></a>类似于MySQL的slow log, MongoDB可以监控所有慢的以及不慢的查询。</p>
<p>Profiler默认是关闭的，你可以选择全部开启，或者有慢查询的时候开启。</p>
<pre class="brush:javascript">&gt; use test
switched to db test
&gt; db.setProfilingLevel(2);
{"was" : 0 , "slowms" : 100, "ok" : 1} // "was" is the old setting
&gt; db.getProfilingLevel()
2</pre>
<p>查看Profile日志</p>
<pre class="brush:javascript">&gt; db.system.profile.find().sort({$natural:-1})
{"ts" : "Thu Jan 29 2009 15:19:32 GMT-0500 (EST)" , "info" :
"query test.$cmd ntoreturn:1 reslen:66 nscanned:0 query: { profile: 2 } nreturned:1 bytes:50" ,
"millis" : 0} ...</pre>
<p>3个字段的意义</p>
<ul>
<li>ts：时间戳</li>
<li>info：具体的操作</li>
<li>millis：操作所花时间，毫秒</li>
</ul>
<p>不多说，此处有<a href="http://www.mongodb.org/display/DOCS/Database+Profiler" target="_blank">官方文档</a>。注意，造成满查询可能是索引的问题，也可能是数据不在内存造成因此磁盘读入造成。</p>
<h1>使用Web控制台</h1>
<p><a href="http://tech.lezi.com/wp-content/uploads/2011/10/mongod-localhost.png"><img class="alignright size-medium wp-image-306" title="mongodb web monitor" src="http://tech.lezi.com/wp-content/uploads/2011/10/mongod-localhost-300x300.png" alt="mongodb web monitor" width="300" height="300" /></a>Mongodb自带了Web控制台，默认和数据服务一同开启。他的端口在Mongodb数据库服务器端口的基础上加1000，如果是默认的Mongodb数据服务端口(Which is 27017)，则相应的Web端口为28017</p>
<p>这个页面可以看到</p>
<ul>
<li>当前Mongodb的所有连接</li>
<li>各个数据库和Collection的访问统计，包括：Reads, Writes, Queries, GetMores ,Inserts, Updates, Removes</li>
<li>写锁的状态</li>
<li>以及日志文件的最后几百行（CentOS+10gen yum 安装的mongodb默认的日志文件位于/var/log/mongo/mongod.log)</li>
</ul>
<p>可以参考右边的截图</p>
<h1>db.stat()</h1>
<p>获取当前数据库的信息，比如Obj总数、数据库总大小、平均Obj大小等</p>
<pre class="brush:javascript">&gt; use test
switched to db test
&gt; db.stats()
{
    "collections" : 9,
    "objects" : 4278845,
    "avgObjSize" : 224.56603031892953,
    "dataSize" : 960883236,
    "storageSize" : 1195438080,
    "numExtents" : 59,
    "indexes" : 13,
    "indexSize" : 801931264,
    "fileSize" : 6373244928,
    "ok" : 1
}</pre>
<h1>db.serverStatus()</h1>
<p>获取服务器的状态</p>
<pre class="brush:javascript">{
    "version" : "1.6.5",
    "uptime" : 7208469,
    "uptimeEstimate" : 7138829,
    "localTime" : "Wed Oct 26 2011 22:23:07 GMT+0800 (CST)",
    "globalLock" : {
        "totalTime" : 7208469556704,
        "lockTime" : 4959693717,
        "ratio" : 0.000688036992871448,
        "currentQueue" : {
            "total" : 0,
            "readers" : 0,
            "writers" : 0
        }
    },
    "mem" : {
        "bits" : 64,
        "resident" : 3131,
        "virtual" : 6172,
        "supported" : true,
        "mapped" : 4927
    },
    "connections" : {
        "current" : 402,
        "available" : 2599
    },
    "extra_info" : {
        "note" : "fields vary by platform",
        "heap_usage_bytes" : 832531920,
        "page_faults" : 8757
    },
    "indexCounters" : {
        "btree" : {
            "accesses" : 2821726,
            "hits" : 2821725,
            "misses" : 1,
            "resets" : 0,
            "missRatio" : 3.543930204420982e-7
        }
    },
    "backgroundFlushing" : {
        "flushes" : 120133,
        "total_ms" : 73235923,
        "average_ms" : 609.6236920746173,
        "last_ms" : 1332,
        "last_finished" : "Wed Oct 26 2011 22:22:23 GMT+0800 (CST)"
    },
    "cursors" : {
        "totalOpen" : 0,
        "clientCursors_size" : 0,
        "timedOut" : 238392
    },
    "repl" : {
        "ismaster" : true
    },
    "opcounters" : {
        "insert" : 269351,
        "query" : 19331151,
        "update" : 14199331,
        "delete" : 1,
        "getmore" : 145575,
        "command" : 55982302
    },
    "asserts" : {
        "regular" : 0,
        "warning" : 0,
        "msg" : 0,
        "user" : 27,
        "rollovers" : 0
    },
    "ok" : 1
}</pre>
<p>需要关心的地方：</p>
<ul>
<li>connections 当前连接和可用连接数，听过一个同行介绍过，mongodb最大处理到2000个连接就不行了（要根据你的机器性能和业务来设定），所以设大了没意义。设个合理值的话，到达这个值mongodb就拒绝新的连接请求，避免被太多的连接拖垮。</li>
<li>indexCounters:btree:misses 索引的不命中数，和hits的比例高就要考虑索引是否正确建立。你看我的”missRatio” : 3.543930204420982e-7，很健康吧。所以miss率在mongostat里面也可以看</li>
<li>其他的都能自解释，也不是查看mongo健康状况的关键，就不说明了。</li>
</ul>
<h1>db.currentOp()</h1>
<p>Mongodb 的命令一般很快就完成，但是在一台繁忙的机器或者有比较慢的命令时，你可以通过db.currentOp()获取当前正在执行的操作。</p>
<p>在没有负载的机器上，该命令基本上都是返回空的</p>
<pre class="brush:javascript">&gt;  db.currentOp()
{ "inprog" : [ ] }</pre>
<p>以下是一个有负载的机器上得到的返回值样例：</p>
<pre class="brush:javascript"> { "opid" : "shard3:466404288", "active" : false, "waitingForLock" : false, "op" : "query", "ns" : "sd.usersEmails", "query" : { }, "client_s" : "10.121.13.8:34473", "desc" : "conn" },</pre>
<p>字段名字都能自解释。如果你发现一个操作太长，把数据库卡死的话，可以用这个命令杀死他</p>
<pre class="brush:javascript">&gt; db.killOp("shard3:466404288")</pre>
<h1>MongoDB Monitoring Service</h1>
<p><a href="http://tech.lezi.com/wp-content/uploads/2011/10/mms.png"><img class="alignnone size-full wp-image-320" title="mms" src="http://tech.lezi.com/wp-content/uploads/2011/10/mms.png" alt="" width="500" height="325" /></a></p>
<p>MongoDB Monitoring Service(MMS)是Mongodb厂商提供的监控服务，可以在网页和Android客户端上监控你的MongoDB状况。请<a href="http://blog.nosqlfan.com/html/3171.html" target="_blank">参考</a></p>

	<h2>您也许会对以下文章感兴趣</h2>
	<ul class="st-related-posts">
	<li><a href="http://tech.lezi.com/archives/116" title="一个不错的MongoDB教程 (十二月 9, 2010)">一个不错的MongoDB教程</a> (评论：2)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://tech.lezi.com/archives/290/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>统计分析svn用户每天提交的代码数</title>
		<link>http://tech.lezi.com/archives/268</link>
		<comments>http://tech.lezi.com/archives/268#comments</comments>
		<pubDate>Wed, 19 Oct 2011 06:44:51 +0000</pubDate>
		<dc:creator>neilxp</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[analyze]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://tech.lezi.com/?p=268</guid>
		<description><![CDATA[这个脚本可以分析svn 用户每天提交的代码数，有了数量的横向比较，也就知道团队里面哪个成员是有很大的潜力提升，帮助其提高。 可以在这里https://gist.github.com/1297604获取最新的代码，复制黏贴到文件里面，chmod +x 后，即可使用。 使用方法： 像下面，获取上一天某账号改动代码的数量 ./svn_ana.sh SVN_ACCOUNT_NAME &#124; wc -l 这里也附上代码，使用前将uname, password用你svn账号的用户名、密码替换 #!/bin/sh # This is a script that help you get your team member's productivity # by analyzing his/her code commiting in SVN repository, for the day before # # You can get a rough num for comparing between team members by [...]]]></description>
			<content:encoded><![CDATA[<p>这个脚本可以分析svn 用户每天提交的代码数，有了数量的横向比较，也就知道团队里面哪个成员是有很大的潜力提升，帮助其提高。</p>
<p>可以在这里<a href="https://gist.github.com/1297604">https://gist.github.com/1297604</a>获取最新的代码，复制黏贴到文件里面，chmod +x 后，即可使用。</p>
<p><span id="more-268"></span></p>
<p>使用方法：</p>
<p>像下面，获取上一天某账号改动代码的数量</p>
<pre class="brush:bash">./svn_ana.sh SVN_ACCOUNT_NAME | wc -l</pre>
<p>这里也附上代码，使用前将uname, password用你svn账号的用户名、密码替换</p>
<pre class="brush:bash">#!/bin/sh
# This is a script that help you get your team member's productivity
# by analyzing his/her code commiting in SVN repository, for the day before
#
# You can get a rough num for comparing between team members by using it in the way below
# ./svn_ana.sh SVN_ACCOUNT_NAME | wc -l
#
uname=vr
password=reader

if [ $# -lt 1 ]
then
	echo Usage: $0 ACCOUNT
	echo -e "   Where ACCOUNT is the SVN acconut name you want to analyze"
	exit -1
fi
user=$1
today=`date +%Y-%m-%d`
yesterday=`date -d '-1 day'  +%Y-%m-%d`
revisions=$(svn log -r{$today}:{$yesterday} --username $uname --password $password |grep $user'\ '|awk '{print $1}')
lastrev=init
for rawrev in $revisions
do
	rev=$(echo $rawrev|tr -d r)
	rev2=`expr $rev - 1`
	if [ "$lastrev" = "init" ]; then
		lastrev=$rev
	fi
	dummy=$(echo $revisions|grep $rev2)
	if [ $? -eq 0 ]
	then
		continue
	fi

	svn diff -r$rev2:$lastrev --username $uname --password $password
	lastrev=init
done</pre>

	<h2>您也许会对以下文章感兴趣</h2>
	<ul class="st-related-posts">
	<li>No related posts.</li>
	</ul>

]]></content:encoded>
			<wfw:commentRss>http://tech.lezi.com/archives/268/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>vim查找文件里面行的长度超过指定值的行</title>
		<link>http://tech.lezi.com/archives/251</link>
		<comments>http://tech.lezi.com/archives/251#comments</comments>
		<pubDate>Mon, 10 Oct 2011 02:37:03 +0000</pubDate>
		<dc:creator>neilxp</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://tech.lezi.com/?p=251</guid>
		<description><![CDATA[查找一行里面超过70个字符的行 /\%>70v.\+ 您也许会对以下文章感兴趣 No related posts.]]></description>
			<content:encoded><![CDATA[<p>查找一行里面超过70个字符的行</p>
<pre class="brush:bash">
/\%>70v.\+
</pre>

	<h2>您也许会对以下文章感兴趣</h2>
	<ul class="st-related-posts">
	<li>No related posts.</li>
	</ul>

]]></content:encoded>
			<wfw:commentRss>http://tech.lezi.com/archives/251/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>用python flup调试nginx fastcgi配置错误造成404的问题</title>
		<link>http://tech.lezi.com/archives/238</link>
		<comments>http://tech.lezi.com/archives/238#comments</comments>
		<pubDate>Tue, 27 Sep 2011 08:16:34 +0000</pubDate>
		<dc:creator>neilxp</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[fastcgi]]></category>
		<category><![CDATA[flup]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://tech.lezi.com/?p=238</guid>
		<description><![CDATA[最近几年php服务器都倾向于使用nginx+fastcgi/php-fpm。 但是配置nginx fastcgi遇到最棘手的问题，就是配置失败时，没有调试手段，不知道哪里有错误，怎么去修改nginx的配置。以前都是盲目尝试，直至配置成功。费时，没有线索。 特别是fastcgi有一堆变量，例如SCRIPT_FILENAME、PATH_INFO、QUERY_STRING、DOCUMENT_URI，如果在配置失败时能看到这些变量的值，对调整配置文件是很有指导意义的。 发现python的flup库有fastcgi的协议解析。用它写了一个小工具，能够打印出fastcgi的所有参数，方便诊断问题。flup的安装不介绍了，脚本内容如下： #!/bin/env python def myapp(environ, start_response): r = '' for x in environ: r+="%s\t%s\n" % (x, environ[x]) print r start_response('200 OK', [('Content-Type', 'text/plain')]) return ['Hello World!\n'] if __name__ == '__main__': from flup.server.fcgi import WSGIServer WSGIServer(myapp,bindAddress=('0.0.0.0', 9999)).run() 使用 用python 前台运行这个脚本 将你的nginx配置里面fastcgi_pass 改成9999端口，重启nginx。 用浏览器触发一个到nginx fastcgi路径的请求 这时python的终端会打印出所有的fastcgi参数 [jw@localhost sk]$ python fastcgi-debug.py wsgi.multiprocess False HTTP_COOKIE [...]]]></description>
			<content:encoded><![CDATA[<p>最近几年php服务器都倾向于使用nginx+fastcgi/php-fpm。</p>
<p>但是配置nginx fastcgi遇到最棘手的问题，就是配置失败时，没有调试手段，不知道哪里有错误，怎么去修改nginx的配置。以前都是盲目尝试，直至配置成功。费时，没有线索。</p>
<p>特别是fastcgi有一堆变量，例如SCRIPT_FILENAME、PATH_INFO、QUERY_STRING、DOCUMENT_URI，如果在配置失败时能看到这些变量的值，对调整配置文件是很有指导意义的。</p>
<p><span id="more-238"></span></p>
<p>发现python的flup库有fastcgi的协议解析。用它写了一个小工具，能够打印出fastcgi的所有参数，方便诊断问题。flup的安装不介绍了，脚本内容如下：</p>
<pre class="brush:python">#!/bin/env python
def myapp(environ, start_response):
    r = ''
    for x in environ:
        r+="%s\t%s\n" % (x, environ[x])
    print r
    start_response('200 OK', [('Content-Type', 'text/plain')])
    return ['Hello World!\n']

if __name__ == '__main__':
    from flup.server.fcgi import WSGIServer
    WSGIServer(myapp,bindAddress=('0.0.0.0', 9999)).run()</pre>
<p>使用</p>
<ol>
<li>用python 前台运行这个脚本</li>
<li>将你的nginx配置里面fastcgi_pass 改成9999端口，重启nginx。</li>
<li>用浏览器触发一个到nginx fastcgi路径的请求</li>
</ol>
<p>这时python的终端会打印出所有的fastcgi参数</p>
<pre class="brush:bash">[jw@localhost sk]$ python fastcgi-debug.py
wsgi.multiprocess	False
HTTP_COOKIE	vvsid=msaI0VbycTSLWFLF0zKmvRZA; orderby=time; last_login=neilxp
REDIRECT_STATUS	200
SERVER_SOFTWARE	nginx/1.0.4
SCRIPT_NAME	index.php
REQUEST_METHOD	GET
PATH_INFO	/xhprof/index.php
SERVER_PROTOCOL	HTTP/1.1
QUERY_STRING
CONTENT_LENGTH
HTTP_ACCEPT_CHARSET	ISO-8859-1,utf-8;q=0.7,*;q=0.3
HTTP_USER_AGENT	Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1
HTTP_CONNECTION	keep-alive
SERVER_NAME	127.0.0.1
REMOTE_PORT	1309
wsgi.url_scheme	http
SERVER_PORT	80
SERVER_ADDR	192.168.7.114
DOCUMENT_ROOT	/home/www/nginx/html
SCRIPT_FILENAME	/home/www/xhprof_html/index.php
DOCUMENT_URI	/xhprof/index.php
wsgi.input
HTTP_HOST	192.168.7.114
wsgi.multithread	True
HTTP_CACHE_CONTROL	max-age=0
REQUEST_URI	/xhprof/index.php
HTTP_ACCEPT	text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
wsgi.version	(1, 0)
GATEWAY_INTERFACE	CGI/1.1
wsgi.run_once	False
wsgi.errors
REMOTE_ADDR	192.168.7.101
HTTP_ACCEPT_LANGUAGE	de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4
CONTENT_TYPE
HTTP_ACCEPT_ENCODING	gzip,deflate,sdch</pre>

	<h2>您也许会对以下文章感兴趣</h2>
	<ul class="st-related-posts">
	<li>No related posts.</li>
	</ul>

]]></content:encoded>
			<wfw:commentRss>http://tech.lezi.com/archives/238/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>一行Linux命令查找所有非UTF-8编码的文件，再一行命令，都转换成UTF-8</title>
		<link>http://tech.lezi.com/archives/194</link>
		<comments>http://tech.lezi.com/archives/194#comments</comments>
		<pubDate>Thu, 06 Jan 2011 14:12:27 +0000</pubDate>
		<dc:creator>neilxp</dc:creator>
				<category><![CDATA[一行Linux命令]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[一行命令]]></category>

		<guid isPermaLink="false">http://tech.lezi.com/?p=194</guid>
		<description><![CDATA[开始之前，请先安装enca这个软件包。enca是Linux等系统下用来查看文件编码和转换文件编码的工具。 下面一行Linux命令能够查找当前目录下所有文件中，哪些文件不是UTF-8编码。我对文件加了些限制，用find命令时候，排除了所有目录下的.svn目录，且只查找后缀为.php的文件。 命令1 jw@~/sqlite&#62; find . ! -iregex '.*\.svn.*' -type f -name '*.php' -exec bash -c "enca -L zh_CN {}&#124;grep GB2312 &#62; /dev/null &#38;&#38; echo {}" \; ./sqlite_utility.php ./sqlite_result.php ./sqlite_forge.php ./sqlite_driver.php 既然找到了这些非UTF8编码的文件，接下来再用一条命令将他们都转换成UTF8编码 命令2 jw@~/sqlite&#62; find . ! -iregex '.*\.svn.*' -type f -name '*.php' -exec bash -c "enca -L zh_CN {} &#124; grep GB2312 &#62;/dev/null &#38;&#38; [...]]]></description>
			<content:encoded><![CDATA[<p>开始之前，请先安装enca这个软件包。enca是Linux等系统下用来查看文件编码和转换文件编码的工具。</p>
<p>下面一行Linux命令能够查找当前目录下所有文件中，哪些文件不是UTF-8编码。我对文件加了些限制，用find命令时候，排除了所有目录下的.svn目录，且只查找后缀为.php的文件。</p>
<p>命令1</p>
<pre class="brush:bash">jw@~/sqlite&gt;
find . ! -iregex '.*\.svn.*' -type f -name '*.php' -exec bash -c "enca -L zh_CN {}|grep GB2312 &gt; /dev/null &amp;&amp; echo {}" \;
./sqlite_utility.php
./sqlite_result.php
./sqlite_forge.php
./sqlite_driver.php</pre>
<p>既然找到了这些非UTF8编码的文件，接下来再用一条命令将他们都转换成UTF8编码</p>
<p>命令2</p>
<pre class="brush:bash">jw@~/sqlite&gt;
find . ! -iregex '.*\.svn.*' -type f -name '*.php' -exec bash -c "enca -L zh_CN {}  | grep GB2312 &gt;/dev/null &amp;&amp; enconv -L zh_CN -x UTF-8 {}" \;</pre>
<p>当你用命令2 全部转换完成后，如果你期待命令1的输出为空，那么你就错了。实际上英语字母的utf8编码和ASCII编码是一样的。当一个全是英文字母的文件用UTF8 w/o BOM编码保存，那么enca会识别他是一个ACSII编码的文件。所以，你猜到了，命令2做了一些无用功:)</p>

	<h2>您也许会对以下文章感兴趣</h2>
	<ul class="st-related-posts">
	<li><a href="http://tech.lezi.com/archives/47" title="解决近期linux下yum更新出现HTTP Error 404 NOT FOUND错误的办法 (十月 28, 2010)">解决近期linux下yum更新出现HTTP Error 404 NOT FOUND错误的办法</a> (评论：3)</li>
	<li><a href="http://tech.lezi.com/archives/40" title="给rdesktop加一个图形界面GUI (十月 27, 2010)">给rdesktop加一个图形界面GUI</a> (评论：0)</li>
	<li><a href="http://tech.lezi.com/archives/75" title="Fedora/Ubuntu Linux下用wine安装腾讯通RTX成功 (十二月 8, 2010)">Fedora/Ubuntu Linux下用wine安装腾讯通RTX成功</a> (评论：1)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://tech.lezi.com/archives/194/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>
