Siege:压力模拟/测试工具

Filed under: 服务器&PC | No Comments »
Posted on

要对一个网站做压力测试,老大说让用siege测试工具,找了一下,发现车东的网站,有这个工具的说明。

从安装到使用,仔细看看以下教程就够了。

以下转自:http://www.chedong.com/blog/archives/000033.html  (加粗的部分,是我改动的)

Siege(英文意思是围攻)是一个压力测试和评测工具,设计用于WEB开发这评估应用在压力下的承受能力:可以根据配置对一个WEB站点进行多用户的并发访问,记录每个用户所有请求过程的相应时间,并在一定数量的并发访问下重复进行。

最早使用的压力测试工具是apache的ab(apache benchmark),apache ab做重复压力测试不错,但是每次只能测试一个链接,如何测试一组链接(比如从日志中导出的1个小时的日志,做真实压力测试),后来找到了这个:
Siege是一个压力测试和评测工具,设计用于WEB开发这评估应用在压力下的承受能力:可以根据配置对一个WEB站点进行多用户的并发访问,记录每个用户所有请求过程的相应时间,并在一定数量的并发访问下重复进行。
SIEGE is an http regressive testing and benchmarking utility. It was designed to let web developers measure the performance of their code under duress, to see how it will stand up to load on the internet. It lets the user hit a webserver with a configurable number of concurrent simulated users. Those users place the webserver “under siege.” The duration of the siege is measured in transactions, the sum of simulated users and the number of times each simulated user repeats the process of hitting the server. Thus 20 concurrent users 50 times is 1000 transactions, the length of the test.

下载/安装
Siege时一个开放源代码项目: http://www.joedog.org

下载:
# wget ftp://sid.joedog.org/pub/siege/siege-latest.tar.gz

解压:

 # tar -zxf siege-latest.tar.gz

进入解压目录:

# cd siege-2.65/

安装:
#./configure ; make
#make install

#siege –help (如果有help出现,则已经安装成功)

siege包含了一组压力测试工具:
SIEGE (1) Siege是一个HTTP压力测试和评测工具.
使用样例:
任务列表:www.chedong.com.url文件
http://www.chedong.com/tech/
http://www.chedong.com/tech/acdsee.html
http://www.chedong.com/tech/ant.html
http://www.chedong.com/tech/apache_install.html
http://www.chedong.com/tech/awstats.html
http://www.chedong.com/tech/cache.html
http://www.chedong.com/tech/click.html
http://www.chedong.com/tech/cms.html
http://www.chedong.com/tech/compress.html
http://www.chedong.com/tech/cvs_card.html
http://www.chedong.com/tech/default.html
http://www.chedong.com/tech/dev.html
http://www.chedong.com/tech/gnu.html
….

siege -c 20 -r 2 -f www.chedong.com.url
参数说明:
-c 20 并发20个用户
-r 2 重复循环2次
-f www.chedong.com.url 任务列表:URL列表

输出样例:

** Siege 2.59
** Preparing 20 concurrent users for battle. 这次“战斗”准备了20个并发用户
The server is now under siege.. done. 服务在“围攻”测试中:
Transactions: 40 hits 完成40次处理
Availability: 100.00 % 成功率
Elapsed time: 7.67 secs 总共用时
Data transferred: 877340 bytes 共数据传输:877340字节
Response time: 1.65 secs 相应用时1.65秒:显示网络连接的速度
Transaction rate: 5.22 trans/sec 平均每秒完成5.22次处理:表示服务器后台处理的速度
Throughput: 114385.92 bytes/sec 平均每秒传送数据:114385.92字节
Concurrency: 8.59 最高并发数 8.59
Successful transactions: 40 成功处理次数
Failed transactions: 0 失败处理次数

注意:由于速度很快,可能会达不到并发速度很高就已经完成。Response time显示的是测试机器和被测试服务器之间网络链接状况。Transaction rate则表示服务器端任务处理的完成速度。

辅助工具:
增量压力测试:
为了方便增量压力测试,siege还包含了一些辅助工具:
bombardment (1)
是一个辅助工具:用于按照增量用户压力测试:
使用样例:
bombardment urlfile.txt 5 3 4 1
初始化URL列表:urlfile.txt
初始化为:5个用户
每次增加:3个用户
运行:4次
每个客户端之间的延迟为:1秒

输出成CSV格式:
siege2csv.pl (1)
siege2csv.pl将bombardment的输出变成CSV格式:
Time Data Transferred Response Time Transaction Rate Throughput Concurrency Code 200 (note that this is horribly broken.)
242 60.22 603064 0.02 4.02 10014.35 0.08
605 59.98 1507660 0.01 10.09 25136.05 0.12
938 59.98 2337496 0.02 15.64 38971.26 0.26
1157 60 2883244 0.04 19.28 48054.07 0.78

参考:
开源测试工具:http://www.opensourcetesting.org/performance.php

压力测试工具:HammerHead 正在试用中

Can’t connect to local MySQL server through socket 解决办法

Filed under: 数据库 | 2 Comments »
Posted on

启动mysql 报错:

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)

1、先查看 /etc/rc.d/init.d/mysqld status 看看m y s q l 是否已经启动.
另外看看是不是权限问题.

2、确定你的mysql.sock是不是在那个位置,
mysql -u 你的mysql用户名 -p -S /var/lib/mysql/mysql.sock

3、试试:service mysqld start

4、如果是权限问题,则先改变权限 #chown -R mysql:mysql /var/lib/mysql

[root@localhost ~]# /etc/init.d/mysqld start
启动 MySQL: [ 确定 ]
[root@localhost ~]# mysql -uroot -p

整理了一下Blog的文章

Filed under: 服务器&PC | No Comments »
Posted on

www.designer5.net 域名已经不再续费了,改成了5.d5s.cn,算是给自己留一个纪念吧,毕竟这是自己刚学会写程序时,做的第一个动态网站。

在准备写blog的时候,当时把 http://5.d5s.cn/ 这个网站的文章,都转载过来了,毕竟这里的文章,也是我之前收集的一些,也许对访问本站的一些朋友,会有帮助,于是就把数据库导过来了,后来发现很多文章,看起来不太好,格式已经变了,一狠心,全部删掉了,留下这些文章的文章,有需要的朋友,就自己找找吧。

以下是之前的一些文章,http://5.d5s.cn/ 这里都有。

详情查看 »

MySQL服务器安装完之后如何调节性能

Filed under: 数据库 | No Comments »
Posted on

innodb_buffer_pool_size – 这对Innodb表来说非常重要。MyISAM可以在默认的 key_buffer_size 设置下运行的可以,然而Innodb在默认的 innodb_buffer_pool_size 设置下却跟蜗牛似的。由于Innodb把数据和索引都缓存起来

转自:http://news.csdn.net/n/20061122/98014.html

My favorite question during Interview for people to work as MySQL DBAs or be involved with MySQL Performance in some way is to ask them what should be tuned in MySQL Server straight after installation, assuming it was installed with default settings.

在面试MySQL DBA或者那些打算做MySQL性能优化的人时,我最喜欢问题是:MySQL服务器按照默认设置安装完之后,应该做哪些方面的调节呢?

I’m surprised how many people fail to provide any reasonable answer to this question, and how many servers are where in wild which are running with default settings.

令我很惊讶的是,有多少人对这个问题无法给出合理的答案,又有多少服务器都运行在默认的设置下。

Even though you can tune quite a lot of variables in MySQL Servers only few of them are really important for most common workload. After you get these settings right other changes will most commonly offer only incremental performance improvements.

尽管你可以调节很多MySQL服务器上的变量,但是在大多数通常的工作负载下,只有少数几个才真正重要。如果你把这些变量设置正确了,那么修改其他变量最多只能对系统性能改善有一定提升。

key_buffer_size – Very important if you use MyISAM tables. Set up to 30-40% of available memory if you use MyISAM tables exclusively. Right size depends on amount of indexes, data size and workload – remember MyISAM uses OS cache to cache the data so you need to leave memory for it as well, and data can be much larger than indexes in many cases. Check however if all of key_buffer is used over time – it is not rare to see key_buffer being set to 4G while combined size of .MYI files is just 1GB. This would be just a waste. If you use few MyISAM tables you’ll want to keep it lower but still at least 16-32Mb so it is large enough to accommodate indexes for temporary tables which are created on disk.

key_buffer_size – 这对MyISAM表来说非常重要。如果只是使用MyISAM表,可以把它设置为可用内存的 30-40%。合理的值取决于索引大小、数据量以及负载 — 记住,MyISAM表会使用操作系统的缓存来缓存数据,因此需要留出部分内存给它们,很多情况下数据比索引大多了。尽管如此,需要总是检查是否所有的 key_buffer 都被利用了 — .MYI 文件只有 1GB,而 key_buffer 却设置为 4GB 的情况是非常少的。这么做太浪费了。如果你很少使用MyISAM表,那么也保留低于 16-32MB 的 key_buffer_size 以适应给予磁盘的临时表索引所需。

innodb_buffer_pool_size This is very important variable to tune if you’re using Innodb tables. Innodb tables are much more sensitive to buffer size compared to MyISAM. MyISAM may work kind of OK with default key_buffer_size even with large data set but it will crawl with default innodb_buffer_pool_size. Also Innodb buffer pool caches both data and index pages so you do not need to leave space for OS cache so values up to 70-80% of memory often make sense for Innodb only installations. Same rules as for key_buffer apply – if you have small data set and it is not going to grow dramatically do not oversize innodb_buffer_pool_size you might find better use for memory available.

innodb_buffer_pool_size – 这对Innodb表来说非常重要。Innodb相比MyISAM表对缓冲更为敏感。MyISAM可以在默认的 key_buffer_size 设置下运行的可以,然而Innodb在默认的 innodb_buffer_pool_size 设置下却跟蜗牛似的。由于Innodb把数据和索引都缓存起来,无需留给操作系统太多的内存,因此如果只需要用Innodb的话则可以设置它高达 70-80% 的可用内存。一些应用于 key_buffer 的规则有 — 如果你的数据量不大,并且不会暴增,那么无需把 innodb_buffer_pool_size 设置的太大了。

innodb_additional_pool_size This one does not really affect performance too much, at least on OS with decent memory allocators. Still you might want to have it 20MB (sometimes larger) so you can see how much memory Innodb allocates for misc needs.

innodb_additional_pool_size – 这个选项对性能影响并不太多,至少在有差不多足够内存可分配的操作系统上是这样。不过如果你仍然想设置为 20MB(或者更大),因此就需要看一下Innodb其他需要分配的内存有多少。

innodb_log_file_size Very important for write intensive workloads especially for large data sets. Larger sizes offer better performance but increase recovery times so be careful. I normally use values 64M-512M depending on server size.

innodb_log_file_size 在高写入负载尤其是大数据集的情况下很重要。这个值越大则性能相对越高,但是要注意到可能会增加恢复时间。我经常设置为 64-512MB,跟据服务器大小而异。

innodb_log_buffer_size Default for this one is kind of OK for many workloads with medium write load and shorter transactions. If you have update activity spikes however or work with blobs a lot you might want to increase it. Do not set it too high however as it would be waste of memory – it is flushed every 1 sec anyway so you do not need space for more than 1 sec worth of updates. 8MB-16MB are typically enough. Smaller installations should use smaller values.

innodb_log_buffer_size 默认的设置在中等强度写入负载以及较短事务的情况下,服务器性能还可以。如果存在更新操作峰值或者负载较大,就应该考虑加大它的值了。如果它的值设置太高了,可能会浪费内存 — 它每秒都会刷新一次,因此无需设置超过1秒所需的内存空间。通常 8-16MB 就足够了。越小的系统它的值越小。

innodb_flush_logs_at_trx_commit Crying about Innodb being 100 times slower than MyISAM ? You probably forgot to adjust this value. Default value of 1 will mean each update transaction commit (or each statement outside of transaction) will need to flush log to the disk which is rather expensive, especially if you do not have Battery backed up cache. Many applications, especially those moved from MyISAM tables are OK with value 2 which means do not flush log to the disk but only flush it to OS cache. The log is still flushed to the disk each second so you normally would not loose more than 1-2 sec worth of updates. Value 0 is a bit faster but is a bit less secure as you can lose transactions even in case MySQL Server crashes. Value 2 only cause data loss with full OS crash.

innodb_flush_logs_at_trx_commit 是否为Innodb比MyISAM慢1000倍而头大?看来也许你忘了修改这个参数了。默认值是 1,这意味着每次提交的更新事务(或者每个事务之外的语句)都会刷新到磁盘中,而这相当耗费资源,尤其是没有电池备用缓存时。很多应用程序,尤其是从 MyISAM转变过来的那些,把它的值设置为 2 就可以了,也就是不把日志刷新到磁盘上,而只刷新到操作系统的缓存上。日志仍然会每秒刷新到磁盘中去,因此通常不会丢失每秒1-2次更新的消耗。如果设置为 0 就快很多了,不过也相对不安全了 — MySQL服务器崩溃时就会丢失一些事务。设置为 2 指挥丢失刷新到操作系统缓存的那部分事务。

table_cache – Opening tables can be expensive. For example MyISAM tables mark MYI header to mark table as currently in use. You do not want this to happen so frequently and it is typically best to size your cache so it is large enough to keep most of your tables open. It uses some OS resources and some memory but for modern hardware it is typically not the problem. 1024 is good value for applications with couple hundreds tables (remember each connection needs its own entry) if you have many connections or many tables increase it larger. I’ve seen values over 100.000 used.

table_cache — 打开一个表的开销可能很大。例如MyISAM把MYI文件头标志该表正在使用中。你肯定不希望这种操作太频繁,所以通常要加大缓存数量,使得足以最大限度地缓存打开的表。它需要用到操作系统的资源以及内存,对当前的硬件配置来说当然不是什么问题了。如果你有200多个表的话,那么设置为 1024 也许比较合适(每个线程都需要打开表),如果连接数比较大那么就加大它的值。我曾经见过设置为 100,000 的情况。

thread_cache Thread creation/destructions can be expensive, which happen at each connect/disconnect. I normally set this value to at least 16. If application has large jumps in amount of concurrent connections and I see fast growth of
Threads_Created variable I boost it higher. The goal is not to have threads created in normal operation.

thread_cache — 线程的创建和销毁的开销可能很大,因为每个线程的连接/断开都需要。我通常至少设置为 16。如果应用程序中有大量的跳跃并发连接并且 Threads_Created 的值也比较大,那么我就会加大它的值。它的目的是在通常的操作中无需创建新线程。

query_cache If your application is read intensive and you do not have application level caches this can be great help. Do not set it too large as it may slow things down as its maintenance may get expensive. Values from 32M to 512M normally make sense. Check it however after a while and see if it is well used. For certain workloads cache hit ratio is lower than would justify having it enabled.

query_cache — 如果你的应用程序有大量读,而且没有应用程序级别的缓存,那么这很有用。不要把它设置太大了,因为想要维护它也需要不少开销,这会导致MySQL变慢。通常设置为 32-512Mb。设置完之后最好是跟踪一段时间,查看是否运行良好。在一定的负载压力下,如果缓存命中率太低了,就启用它。

Note: as you can see all of these are global variables. These variables depend on hardware and mix of storage engines, while per session variables are typically workload specific. If you have simple queries there is no reason to increase sort_buffer_size even if you have 64GB of memory to waste. Furthermore doing so may decrease performance.
I normally leave per session variable tuning to second step after I can analyze workload.

注意:就像你看到的上面这些全局表量,它们都是依据硬件配置以及不同的存储引擎而不同,但是会话变量通常是根据不同的负载来设定的。如果你只有一些简单的查询,那么就无需增加 sort_buffer_size 的值了,尽管你有 64GB 的内存。搞不好也许会降低性能。
我通常在分析系统负载后才来设置会话变量。

P.S Note MySQL distribution contains bunch of sample my.cnf files which may be great templates to use. Typically they would already be much better than defaults if you chose correct one.

P.S,MySQL的发行版已经包含了各种 my.cnf 范例文件了,可以作为配置模板使用。通常这比你使用默认设置好的多了。

jquery和prototype的比较,以及冲突解决

Filed under: 交互设计, 程序 | 2 Comments »
Posted on

初次试用jQuery,到底是prototype好还是jquery好?之前的项目已经使用了prototype,现加入jquery后,立刻罢工,搜了一下,还是有解决办法的(原文),不过最后我还是抛弃prototype,开始使用jquery了。

<script src=”prototype.js” mce_src=”prototype.js”></script>
<script src=”http://blogbeta.blueidea.com/jquery.js” mce_src=”http://blogbeta.blueidea.com/jquery.js”></script>
<script type=”text/javascript”>
      jQuery.noConflict();
</script>

注意:一定要先引入prototype.js 再引入jquery.js,先后顺序不可错。

如果先包含jQuery,将引起代码终止,作为提醒,jQuery将抛出一个异常:“You are overwriting jQuery, please include jQuery  last.”

 prototype中最方便的函数莫过于

<input id=”blueidea” value=”蓝色” type=”text” />
$(”blueidea”)   ===  document.getElementById(”blueidea”)    某id的对象

$F(”blueidea”)   ===  document.getElementById(”blueidea”).value   表单的值

如今使用jquery,这些都没有了。

$(”#id”) 这样虽然也可以获得某id的对象,但是不能对此id进行常规的js操作。(也许有方法,不过我还不会。)

例如

<input id=”blue” value=”蓝色” type=”text” />
<div id=”idea”>蓝色理想</div>

现在改为

id=”blue”的值”蓝色”改为 “经典”;
id=”idea”的节点文字”蓝色理想”改为”<b>经典论坛</b>”

prototype写法:
$(”blue”) .value=”http://blogbeta.blueidea.com/经典”;
$(”idea”).innerHTML=”<b>经典论坛</b>”;  或者
Element.update(”idea”, “<b>经典论坛</b>”);

这些都不能这么写,而要用

jquery写法:
$(”#blue”) .val(”经典”);

$(”#idea”).empty();    //先置空此元素
$(”#idea”).append(”<b>经典论坛</b>”);    //再添加新的字符串

如果你把prototype换成jquery了,但是还想使用prototype中的方便函数

建议自己定义两个函数

function $G(id){
 return document.getElementById(id);
}
function $F(id){
 return $G(id).value;
}

以前的javascript思想要改变了,用了jquery一切就要jquery的规范来,好处就是不用担心浏览器兼容性了,反正用的是jquery的函数,不兼容就是他的问题了,如果是自己随意写,就有浏览器的兼容性问题。

目前为止prototype最方便就是有chm手册,查询起来很方便,而jquery只有英文的api文档,虽然也不错,但还是期待jquery的中文chm。

mysql 删除表中的重复记录,只保留其中一条

Filed under: 程序 | No Comments »
Posted on

查询重复记录 select * from table GROUP BY name 

只把有重复的显示出来
select * ,count(*) as nums from tab_a group by name having nums>1

方法一:(这个方法比较不错,只是自增字段会重建)

  新建一个临时表  
  create   table   tmp   as   select   *   from   youtable   group   by   name  
  删除原来的表  
  drop   table   youtable  
  重命名表  
  alter   table   tmp   rename   youtable

方法二:(未试过)

CREATE TEMPORARY TABLE
bad_temp2(id VARCHAR(10), name VARCHAR(20))
TYPE=HEAP;

INSERT INTO bad_temp2(name) SELECT DISTINCT name FROM bad_table2;

DELETE FROM bad_table2;

INSERT INTO bad_table2(id,name) SELECT id,name FROM bad_temp2;

以上方法采用建立临时表的办法删除了 bad_table2 中 name 字段有重复的记录。

MySQL server has gone away 解决办法

Filed under: 数据库 | No Comments »
Posted on

有时候使用MySQL命令行导入备份时会出现“MySQL server has gone away”错误,这可能是因为其中一些insert语句的大小超出了mysql目前设置的缓冲区大小。

解决办法

1.使用phpmyadmin 备份mysql的时候,只选择


    

    

批量更新记录的时间

Filed under: 程序 | No Comments »
Posted on
下载: timer.js
  1. <?php
  2.     $list_num = 5;    //每5条记录更新一次时间
  3.     $sum = 100;        //共100条
  4.     $time = time();   //初始时间
  5.     for ($i=0; $i<$sum; $i++){
  6.         $str = $i." = ";
  7.         if (($i) % $list_num ==0) {
  8.             echo "<hr>";
  9.             $time = $time+3600*24;
  10.         }else{
  11.             $time = $time;
  12.         }
  13.         $str.= $time." = ".date("Y-m-d H:i:s", $time)."<br/>";
  14.         //"UPDATE `table` SET timer = '$time' WHERE id = ".$i;
  15.         echo $str;
  16.     }
  17. ?>

wordpress 分页错误

Filed under: 程序 | No Comments »
Posted on

SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts WHERE 1=1 AND (post_type = ‘post’ AND (post_status = ‘publish’ OR post_status = ‘private’)) ORDER BY post_date DESC LIMIT 0, 10

这个错误的解决办法

修改 模版下面的 pagination.php 文件

把这个preg_match(’#FROM\s(.*)\sGROUP BY#siU’, $request, $matches);

改为

preg_match(’#FROM\s(.*)\sORDER BY#siU’, $request, $matches);

然后上传 pagination.php 即可。

具体你可以这样调试

echo $request;
echo ‘<pre>’;
print_r($matches);
echo ‘</pre>’;

把这个打印出来看看,可能是正则错误了。

php中加入了时区的设置,造成了我们中国的用户会差八个小时的问题

Filed under: 程序 | 2 Comments »
Posted on

从php5.10开始,php中加入了时区的设置,在php中显示的时间都是格林威治标准时间,这就造成了我们中国的用户会差八个小时的问题!  

  [Date]  
  ;date.timezone   =  
  默认是关闭的,只需把注释去掉,改为 Asia/Hong_Kong 即可  
  ;   Defines   the   default   timezone   used   by   the   date   functions  
    date.timezone = Asia/Hong_Kong

  其他选项可以参考php手册。  
   
  也可以调用date_default_timezone_get()来查看当前的时区设置!  
  中国內地可用的值是:  
  中国港台地區可用:Asia/Macao   ,Asia/Hong_Kong   ,Asia/Taipei   (依次為澳門,香港,台北)  
  还有新加坡:Asia/Singapore  

分页: Prev 1 2 3 ...5 6 7 8 9 10 11 12 13
972 垃圾评论
截获自
Akismet