2009年12月30日

c++ difference from java
1. take charge of object management , negotiate ownershiop ,use scoped_ptr,
   not to transfer other's ownership
2. use c++ template to express seperation corncern ,such as (static)polymorphy and policy
3. disable copy constructor and assign operator by yourself
4. polymorphy by pointer
5. 使用 template ,macro 取得类似动态语言的能力
6. 偏好无状态的 函数
posted @ 2010-02-03 11:43 西津渡 阅读(253) | 评论 (0)编辑 收藏
 
    只有注册用户登录后才能阅读该文。阅读全文
posted @ 2010-01-15 12:22 西津渡 阅读(99) | 评论 (0)编辑 收藏
 

Myisam is preferred without transaction and little update(delete)

Big than 4G datafile can user Myisam merge table.

InnoDB with auto_increment primary key is preferred.

Few storage process

Guess: 20m records max per table , 500G data max per tablespace , 256 tables per database (may problem)

Use prepared statement and  batch

Optimize Your Queries For the Query Cache

// query cache does NOT work
$r = mysql_query("SELECT username FROM user WHERE signup_date >= CURDATE()");
 
// query cache works!
$today = date("Y-m-d");
$r = mysql_query("SELECT username FROM user WHERE signup_date >= '$today'");

EXPLAIN Your SELECT Queries

LIMIT 1 When Getting a Unique Row

Index and Use Same Column Types for Joins

Do Not ORDER BY RAND()

Avoid SELECT *

t is a good habit to always specify which columns you need when you are doing your SELECT’s.

Use ENUM over VARCHAR

Use NOT NULL If You Can

Store IP Addresses as UNSIGNED INT (?)

Fixed-length (Static) Tables are Faster

Vertical Partitioning

Vertical Partitioning is the act of splitting your table structure in a vertical manner for optimization reasons.

Example 1: You might have a users table that contains home addresses, that do not get read often. You can choose to split your table and store the address info on a separate table. This way your main users table will shrink in size. As you know, smaller tables perform faster.

Example 2: You have a “last_login” field in your table. It updates every time a user logs in to the website. But every update on a table causes the query cache for that table to be flushed. You can put that field into another table to keep updates to your users table to a minimum.

But you also need to make sure you don’t constantly need to join these 2 tables after the partitioning or you might actually suffer performance decline.

Split the Big DELETE or INSERT Queries

If you have some kind of maintenance script that needs to delete large numbers of rows, just use the LIMIT clause to do it in smaller batches to avoid this congestion.

Smaller Columns Are Faster

Use an Object Relational Mapper

f you do not need the time component, use DATE instead of DATETIME.

Consider horizontally spitting many-columned tables if they contain a lot of NULLs or rarely used columns.

Be an SQL programmer who thinks in sets, not procedural programming paradigms

InnoDB can’t optimize SELECT COUNT(*) queries. Use counter tables! That’s how to scale InnoDB.

Prefer MM with hive

refer :

http://blog.tuvinh.com/top-20-mysql-best-practices/

posted @ 2010-01-05 13:38 西津渡 阅读(381) | 评论 (0)编辑 收藏
 
    只有注册用户登录后才能阅读该文。阅读全文
posted @ 2010-01-04 15:11 西津渡 阅读(76) | 评论 (0)编辑 收藏
 

从时序图中可以看到,createNewIO()就是新建了一个com.mysql.jdbc.MysqlIO,利用 com.mysql.jdbc.StandardSocketFactory来创建一个socket。然后就由这个mySqlIO来与MySql服务器进行握手(doHandshake()),这个doHandshake主要用来初始化与Mysql server的连接,负责登陆服务器和处理连接错误。在其中会分析所连接的mysql server的版本,根据不同的版本以及是否使用SSL加密数据都有不同的处理方式,并把要传输给数据库server的数据都放在一个叫做packet的 buffer中,调用send()方法往outputStream中写入要发送的数据。


useServerPreparedStmts置为true的话,mysql驱动可以通过PreparedStatement的子类ServerPreparedStatement来实现真正的PreparedStatement的功能




第一位表示数据包的开始位置,就是数据存放的起始位置,一般都设置为0,就是从第一个位置开始。第二和第三个字节标识了这个数据包的大小,注意的是,这个大小是出去标识的4个字节的大小,对于非最后一个数据包来说,这个大小都是一样的,就是splitSize,也就是maxThreeBytes,它的值是 255 * 255 * 255。
最后一个字节中存放的就是数据包的编号了,从0开始递增。
在标识位设置完毕之后,就可以把255 * 255 * 255大小的数据从我们准备好的待发送数据包中copy出来了,注意,前4位已经是标识位了,所以应该从第五个位置开始copy数据

 # packetToSend = compressPacket(headerPacket, HEADER_LENGTH,    
#                 splitSize, HEADER_LENGTH); 

LoadBalancingConnectionProxy
package java.lang.reflect 。 proxy .


http://developer.51cto.com/art/200907/137823.htm

http://dev.mysql.com/doc/refman/5.1/en/connector-j-reference-implementation-notes.html

PreparedStatements are implemented by the driver, as MySQL does not have a prepared statement feature. Because of this, the driver does not implement getParameterMetaData() or getMetaData() as it would require the driver to have a complete SQL parser in the client.

Starting with version 3.1.0 MySQL Connector/J, server-side prepared statements and binary-encoded result sets are used when the server supports them.


但这是不是说PreparedStatement没用呢?不是的,PreparedStatement有其他的好处:
1.代码的可读性和可维护性
2.最重要的一点是极大地提高了安全性,可以防止SQL注入

然后我又看了一些网上其他人的经验,基本和我的判断一致,有两点要特别提请大家注意:

1.并不是说PreparedStatement在所有的DB上都不会提高效率,PreparedStatement需要服务器端的支持,比如在 Oracle上就会有显著效果。上面说的测试都是在MySQL上测试的,我找到了一个MySQL架构师的帖子,比较明确地说明了MySQL不支持 PreparedStatement。

2.即便PreparedStatement不能提高性能,在少数使用时甚至会降低效率,但仍然应该使用PreparedStatement!因为其他好 处实在是太大了!当然,当SQL查询比较复杂时,可能PreparedStatement好处会更大,只是我没有测试,不敢肯定。

3.既然PreparedStatement不能提高效率,那PreparedStatement Pool也就没有必要了。但可以看到每次新建Connection的开销实在很大,因此Connection Pool绝对必要。



posted @ 2009-12-30 12:41 西津渡 阅读(375) | 评论 (0)编辑 收藏