<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[张宴的博客]]></title> 
<link>http://zyan.cc/index.php</link> 
<description><![CDATA[Web系统架构与底层研发]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[张宴的博客]]></copyright>
<item>
<link>http://zyan.cc/tcsql/</link>
<title><![CDATA[为列表页缓存而生：TCSQL实时列表缓存数据库帮助文档[原创]]]></title> 
<author>张宴 &lt;net@s135.com&gt;</author>
<category><![CDATA[数据库技术]]></category>
<pubDate>Fri, 25 Sep 2009 05:27:07 +0000</pubDate> 
<guid>http://zyan.cc/tcsql/</guid> 
<description>
<![CDATA[ 
	　　[文章作者：张宴 本文版本：v1.1 最后修改：2010.09.03 转载请注明原文链接：<a href="http://blog.zyan.cc/tcsql/" target="_blank">http://blog.zyan.cc/tcsql/</a>]<br/><br/>　　曾经有人提出，一般数据库缓存分为四种。第一种：单个对象的缓存（一个对象就是数据库一条记录），对于单个对象的临时缓存或永久缓存，用HashMap就可以了，Key-Value方式的Memcached、Memcachedb、Tokyo Tyrant都可以，或者直接对查询数据库的网页采用Squid做缓存，没什么太难的；第二种：列表缓存，就像论坛里帖子的列表；第三种：记录条数的缓存，比如一个论坛板块里有多少个帖子，这样才方便实现分页。第四种：复杂一点的group，sum，count查询，比如一个论坛里按点击数排名的最HOT的帖子列表。第一种比较好实现，后面三种比较困难，虽然可以通过各种方法来解决，但截至目前，似乎还没有使用即简单、并发处理能力又强、实时性又高的解决办法。<br/><br/><hr/><br/>　　TCSQL为列表页的实时缓存而生，是金山逍遥网技术支持部平台组以Tokyo Cabinet DBM为底层存储与索引，结合类似Memcached的Key-Value内存对象缓存，借鉴SQL语句的SELECT、INSERT、UPDATE、DELETE思想与功能开发的实时列表缓存数据库，能够较好地解决上述前三种类别，特别是第二种、第三种类别的高并发读写问题。<br/><br/>　　TCSQL采用HTTP GET/POST协议＋JSON数据交换格式在客户端、服务器端之间进行数据交互，支持HTTP协议的任何客户端或语言（例如JavaScript、PHP、JSP、Perl、Python等），都能够连接TCSQL服务器进行操作。这就意味着，一些查询量非常大的应用，甚至可以直接使用运行在用户浏览器端的JavaScript代码访问TCSQL数据库，当然，为了安全起见，你可以在中间用Nginx配以rewrite规则，对TCSQL做个反向代理，限制一下查询权限。<br/><br/>　　利用开源的MySQL UDF自定义函数扩展lib_mysqludf_urlencode、lib_mysqludf_urlencode，以及我们平台组周洋同学编写的lib_mysqludf_http_post扩展，配以MySQL触发器，我们可以在MySQL的某张表发生插入、更新、删除操作时，自动将数据同步到TCSQL数据库，使得TCSQL可以当MySQL从库一样使用。<br/><br/>　　TCSQL实时列表缓存数据库单机能够支撑1万以上的并发连接，QPS（每秒查询率）能够达到5000～15000次。<br/><br/><a href="http://zyan.cc/attachment.php?fid=27" target="_blank"><img src="http://zyan.cc/attachment.php?fid=27" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/><br/>　　以下是TCSQL在10000并发连接情况下的查询速度（服务器为浪潮NF190服务器，两颗双核Xeon(TM) CPU 2.80GHz、4GB内存、1万转SCSI硬盘。）：<br/><br/>　　1、第一种类型A：主键查询并取出倒序第1条记录（“=”运算）：<span style="color: #FF0000;">12155次请求/秒</span><br/><br/>　　查询内容：<a href="http://192.168.8.34:3888/?command=select&type=" target="_blank">http://192.168.8.34:3888/?command=select&type=</a>*&where=pkey:NUMEQ:随机数值&order_by=pkey&order_sort=NUMDESC&limit_skip=0&limit_max=1<br/><br/>　　测试结果：<br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">Benchmarking: 10000 clients, running 60 sec.<br/><br/>Speed=729324 pages/min, 8031913 bytes/sec.<br/>Requests: 60777 susceed, 0 failed.</div></div><br/><br/>　　2、第一种类型B：其他索引键查询并取出倒序第1条记录（“=”运算）：<span style="color: #FF0000;">11897次请求/秒</span><br/><br/>　　查询内容：<a href="http://192.168.8.34:3888/?command=select&type=" target="_blank">http://192.168.8.34:3888/?command=select&type=</a>*&where=uid:NUMEQ:随机数值&order_by=pkey&order_sort=NUMDESC&limit_skip=0&limit_max=1<br/><br/>　　测试结果：<br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">Benchmarking: 10000 clients, running 60 sec.<br/><br/>Speed=713856 pages/min, 7865884 bytes/sec.<br/>Requests: 59488 susceed, 0 failed.</div></div><br/><br/>　　3、第二种类型：根据复合条件查询并取出倒序前10条记录：<span style="color: #FF0000;">8778次请求/秒</span>（相当于SELECT * FROM table WHERE dateline >= 随机时间戳 AND idtype = '变换的文本' ORDER BY pkey DESC LIMIT 0,10）<br/><br/>　　查询内容：<a href="http://192.168.8.34:3888/?command=select&type=" target="_blank">http://192.168.8.34:3888/?command=select&type=</a>*&where=dateline:NUMGE:随机时间戳&#124;idtype:STREQ:变换的文本&order_by=pkey&order_sort=NUMDESC&limit_skip=0&limit_max=10<br/><br/>　　测试结果：<br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">Benchmarking: 10000 clients, running 60 sec.<br/><br/>Speed=526680 pages/min, 8971878 bytes/sec.<br/>Requests: 43890 susceed, 0 failed.</div></div><br/><br/>　　4、第三种类型：统计符合查询条件的记录数量：<span style="color: #FF0000;">9160次请求/秒</span>（相当于SELECT count(*) FROM table WHERE dateline >= 随机时间戳 AND idtype = '变换的文本'）<br/><br/>　　查询内容：<a href="http://192.168.8.34:3888/?command=select&type=count&where=dateline:NUMGE:" target="_blank">http://192.168.8.34:3888/?command=select&type=count&where=dateline:NUMGE:</a>随机时间戳&#124;idtype:STREQ:变换的文本<br/><br/>　　测试结果：<br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">Benchmarking: 10000 clients, running 5 sec.<br/><br/>Speed=549648 pages/min, 714542 bytes/sec.<br/>Requests: 45804 susceed, 0 failed.</div></div><br/><br/><br/>............<br/><br/>Tags - <a href="http://zyan.cc/tags/tcsql/" rel="tag">tcsql</a> , <a href="http://zyan.cc/tags/tokyocabinet/" rel="tag">tokyocabinet</a> , <a href="http://zyan.cc/tags/tokyo/" rel="tag">tokyo</a> , <a href="http://zyan.cc/tags/cabinet/" rel="tag">cabinet</a> , <a href="http://zyan.cc/tags/tc/" rel="tag">tc</a> , <a href="http://zyan.cc/tags/memcached/" rel="tag">memcached</a> , <a href="http://zyan.cc/tags/linux/" rel="tag">linux</a> , <a href="http://zyan.cc/tags/mysqludf/" rel="tag">mysqludf</a> , <a href="http://zyan.cc/tags/mysql/" rel="tag">mysql</a> , <a href="http://zyan.cc/tags/http/" rel="tag">http</a> , <a href="http://zyan.cc/tags/cache/" rel="tag">cache</a> , <a href="http://zyan.cc/tags/select/" rel="tag">select</a> , <a href="http://zyan.cc/tags/insert/" rel="tag">insert</a> , <a href="http://zyan.cc/tags/delete/" rel="tag">delete</a> , <a href="http://zyan.cc/tags/update/" rel="tag">update</a>
]]>
</description>
</item><item>
<link>http://zyan.cc/tcsql/#blogcomment4092</link>
<title><![CDATA[[评论] 为列表页缓存而生：TCSQL实时列表缓存数据库帮助文档[原创]]]></title> 
<author>Willko &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 25 Sep 2009 07:40:18 +0000</pubDate> 
<guid>http://zyan.cc/tcsql/#blogcomment4092</guid> 
<description>
<![CDATA[ 
	看上去比较像在tc本身的检索功能上，提供sql适配器。不知道是否理解正确
]]>
</description>
</item><item>
<link>http://zyan.cc/tcsql/#blogcomment4093</link>
<title><![CDATA[[评论] 为列表页缓存而生：TCSQL实时列表缓存数据库帮助文档[原创]]]></title> 
<author>小宝 &lt;ilsanbao@163.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 25 Sep 2009 08:57:36 +0000</pubDate> 
<guid>http://zyan.cc/tcsql/#blogcomment4093</guid> 
<description>
<![CDATA[ 
	好文章,学习学习！
]]>
</description>
</item><item>
<link>http://zyan.cc/tcsql/#blogcomment4094</link>
<title><![CDATA[[评论] 为列表页缓存而生：TCSQL实时列表缓存数据库帮助文档[原创]]]></title> 
<author>nicidoggy &lt;nicidoggy@gmail.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 25 Sep 2009 10:53:19 +0000</pubDate> 
<guid>http://zyan.cc/tcsql/#blogcomment4094</guid> 
<description>
<![CDATA[ 
	好久没更新，一更新就真么长
]]>
</description>
</item><item>
<link>http://zyan.cc/tcsql/#blogcomment4095</link>
<title><![CDATA[[评论] 为列表页缓存而生：TCSQL实时列表缓存数据库帮助文档[原创]]]></title> 
<author>blue &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 25 Sep 2009 11:22:14 +0000</pubDate> 
<guid>http://zyan.cc/tcsql/#blogcomment4095</guid> 
<description>
<![CDATA[ 
	能开源就好了.
]]>
</description>
</item><item>
<link>http://zyan.cc/tcsql/#blogcomment4096</link>
<title><![CDATA[[评论] 为列表页缓存而生：TCSQL实时列表缓存数据库帮助文档[原创]]]></title> 
<author>airwin &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 25 Sep 2009 11:24:35 +0000</pubDate> 
<guid>http://zyan.cc/tcsql/#blogcomment4096</guid> 
<description>
<![CDATA[ 
	这个以后会放出来吗?~
]]>
</description>
</item><item>
<link>http://zyan.cc/tcsql/#blogcomment4098</link>
<title><![CDATA[[评论] 为列表页缓存而生：TCSQL实时列表缓存数据库帮助文档[原创]]]></title> 
<author>jiangjun &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 25 Sep 2009 13:02:42 +0000</pubDate> 
<guid>http://zyan.cc/tcsql/#blogcomment4098</guid> 
<description>
<![CDATA[ 
	呵呵，越来越高深了～～～
]]>
</description>
</item><item>
<link>http://zyan.cc/tcsql/#blogcomment4099</link>
<title><![CDATA[[评论] 为列表页缓存而生：TCSQL实时列表缓存数据库帮助文档[原创]]]></title> 
<author>dengjiuhong &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 25 Sep 2009 13:48:17 +0000</pubDate> 
<guid>http://zyan.cc/tcsql/#blogcomment4099</guid> 
<description>
<![CDATA[ 
	tc 很强大，最近开发的项目大量用到。
]]>
</description>
</item><item>
<link>http://zyan.cc/tcsql/#blogcomment4100</link>
<title><![CDATA[[评论] 为列表页缓存而生：TCSQL实时列表缓存数据库帮助文档[原创]]]></title> 
<author>lnnujxxy &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 25 Sep 2009 14:29:00 +0000</pubDate> 
<guid>http://zyan.cc/tcsql/#blogcomment4100</guid> 
<description>
<![CDATA[ 
	希望以后能提供详细的线上的运行数据
]]>
</description>
</item><item>
<link>http://zyan.cc/tcsql/#blogcomment4105</link>
<title><![CDATA[[评论] 为列表页缓存而生：TCSQL实时列表缓存数据库帮助文档[原创]]]></title> 
<author>k &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Sat, 26 Sep 2009 13:54:49 +0000</pubDate> 
<guid>http://zyan.cc/tcsql/#blogcomment4105</guid> 
<description>
<![CDATA[ 
	没什么特别的
]]>
</description>
</item><item>
<link>http://zyan.cc/tcsql/#blogcomment4108</link>
<title><![CDATA[[评论] 为列表页缓存而生：TCSQL实时列表缓存数据库帮助文档[原创]]]></title> 
<author>kgl &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Sun, 27 Sep 2009 09:32:13 +0000</pubDate> 
<guid>http://zyan.cc/tcsql/#blogcomment4108</guid> 
<description>
<![CDATA[ 
	能否具体说明一下利用key-value建立索引过程和策略，毕竟涉及到客户端查询取值模糊匹配的结果集返回，感觉这个应该是此应用的核心，谢谢！~
]]>
</description>
</item><item>
<link>http://zyan.cc/tcsql/#blogcomment4114</link>
<title><![CDATA[[评论] 为列表页缓存而生：TCSQL实时列表缓存数据库帮助文档[原创]]]></title> 
<author>dreamfly_1981 &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Mon, 28 Sep 2009 11:44:29 +0000</pubDate> 
<guid>http://zyan.cc/tcsql/#blogcomment4114</guid> 
<description>
<![CDATA[ 
	你好。我的站也是uchome2.0建立的。可以讲一下。你们的feed操作是如何通过TCSQL来实现的。<br/>tcsql是部署在同一台和mysql 相同的服务器还是在不同的服务器。谢谢了
]]>
</description>
</item><item>
<link>http://zyan.cc/tcsql/#blogcomment4115</link>
<title><![CDATA[[评论] 为列表页缓存而生：TCSQL实时列表缓存数据库帮助文档[原创]]]></title> 
<author>最美别墅 &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Mon, 28 Sep 2009 13:42:46 +0000</pubDate> 
<guid>http://zyan.cc/tcsql/#blogcomment4115</guid> 
<description>
<![CDATA[ 
	终于看到更新文章了。<br/>不错的优化数据库读写效率的好文章。很多开源的东西如果结合的好，并适当地发挥各自的优点，的确可以事半功倍。感谢张宴的开源共享精神。
]]>
</description>
</item><item>
<link>http://zyan.cc/tcsql/#blogcomment4120</link>
<title><![CDATA[[评论] 为列表页缓存而生：TCSQL实时列表缓存数据库帮助文档[原创]]]></title> 
<author>kitsudo &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Tue, 29 Sep 2009 06:45:00 +0000</pubDate> 
<guid>http://zyan.cc/tcsql/#blogcomment4120</guid> 
<description>
<![CDATA[ 
	这个很好很强大
]]>
</description>
</item><item>
<link>http://zyan.cc/tcsql/#blogcomment4129</link>
<title><![CDATA[[评论] 为列表页缓存而生：TCSQL实时列表缓存数据库帮助文档[原创]]]></title> 
<author>太阳里的雪 &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Mon, 05 Oct 2009 05:25:29 +0000</pubDate> 
<guid>http://zyan.cc/tcsql/#blogcomment4129</guid> 
<description>
<![CDATA[ 
	这个用内存数据库（Timesten）等不能够更好的实现？
]]>
</description>
</item><item>
<link>http://zyan.cc/tcsql/#blogcomment4158</link>
<title><![CDATA[[评论] 为列表页缓存而生：TCSQL实时列表缓存数据库帮助文档[原创]]]></title> 
<author>crunch &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Sat, 10 Oct 2009 00:34:39 +0000</pubDate> 
<guid>http://zyan.cc/tcsql/#blogcomment4158</guid> 
<description>
<![CDATA[ 
	能有python接口就好。
]]>
</description>
</item>
</channel>
</rss>