解决方案 »

  1.   

    贴出 explain select * from tweets where timeandid='2014-03-23+08:51:151309969322';
    及 show index from tweets以供分析。
      

  2.   

    这里是信息,请版主大人帮帮忙,这是explain那条查询语句
    +----+-------------+--------+------+---------------+------+---------+-------+------+-------------+
    | id | select_type | table  | type | possible_keys | key  | key_len | ref   | rows | Extra       |
    +----+-------------+--------+------+---------------+------+---------+-------+------+-------------+
    |  1 | SIMPLE      | tweets | ref  | try           | try  | 130     | const |    1 | Using where |
    +----+-------------+--------+------+---------------+------+---------+-------+------+-------------+
    1 row in set (0.65 sec)
    这个是showindex
    --------+----------+--------+------+------------+---------+---------------+
    | Table  | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
    +--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
    | tweets |          1 | try      |            1 | timeandid   | A         |   204543003 |     NULL | NULL   |      | BTREE      |         |               |
    +--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
    1 row in set (5.17 sec)
      

  3.   

    然后以下是我做的测试:
    1、把my.cnf里面
          1)back_log调成10240
          2)max_connection = 1024
          3) key_buffer_size = 512mb
    2、在进行load测试的时候(每秒万条请求),查看系统进程和内存占用,发现tomcat占用CPU约为10%,占用内存2%,mysql占用cpu 0%, 占用内存0.8%。
    3、在mysql里面show processlist,很多进程的time为8-10秒的等待
    4、myisam和innodb引擎全部进行过测试,结果一样,都是每秒处理10条-30条,离要求的5000条相差甚远
    5、进行时间测试,发现时间查询时间越来越长,1分钟后,约为6秒一条之后我将数据库内容全部清空
    再次进行测试,查询时间明显缩短,并且没有随时间上升的趋势,1分钟内从0ms-8ms不等,没有超过8ms的语句,当然因为数据库是空,返回的都是不正确结果
      

  4.   

    另外,我随机取出一条语句进行查询,查询耗时从0.00s--0.50s不等;
    我使用tomcat连接池进行200个连接池初始化,启动tomcat后show processlist会有200个进程sleep,但是测试的时候并没有全部利用,仍然有100个进程在sleep