AMQP AMQP协议是一个高级抽象层消息通信协议,RabbitMQ是AMQP协议的实现。它主要包括以下组件: 1.Server(broker): 接受客户端连接,实现AMQP消息队列和路由功能的进程。 2.Virtual Host:其实是一个虚拟概念,类似于权限控制组,一个Virtual Host里面可以有若干个Exchange和Queue,但是权限控制的最小粒度是Virtual Host 3.Exchange:接受生产者发送的消息,并根据Binding规则将消息路由给服务器中的队列。ExchangeType决定了Exchange路由消息的行为,例如,在RabbitMQ中,ExchangeType有direct、Fanout和Topic三种,不同类型的Exchange路由的行为是不一样的。 4.Message Queue:消息队列,用于存储还未被消费者消费的消息。 5.Message: 由Header和Body组成,Header是由生产者添加的各种属性的集合,包括Message是否被持久化、由哪个Message Queue接受、优先级是多少等。而Body是真正需要传输的APP数据。 6.Binding:Binding联系了Exchange与Message Queue。Exchange在与多个Message Queue发生Binding后会生成一张路由表,路由表中存储着Message Queue所需消息的限制条件即Binding Key。当Exchange收到Message时会解析其Header得到Routing Key,Exchange根据Routing Key与Exchange Type将Message路由到Message Queue。Binding Key由Consumer在Binding Exchange与Message Queue时指定,而Routing Key由Producer发送Message时指定,两者的匹配方式由Exchange Type决定。 7.Connection:连接,对于RabbitMQ而言,其实就是一个位于客户端和Broker之间的TCP连接。 8.Channel:信道,仅仅创建了客户端到Broker之间的连接后,客户端还是不能发送消息的。需要为每一个Connection创建Channel,AMQP协议规定只有通过Channel才能执行AMQP的命令。一个Connection可以包含多个Channel。之所以需要Channel,是因为TCP连接的建立和释放都是十分昂贵的,如果一个客户端每一个线程都需要与Broker交互,如果每一个线程都建立一个TCP连接,暂且不考虑TCP连接是否浪费,就算操作系统也无法承受每秒建立如此多的TCP连接。RabbitMQ建议客户端线程之间不要共用Channel,至少要保证共用Channel的线程发送消息必须是串行的,但是建议尽量共用Connection。 9.Command:AMQP的命令,客户端通过Command完成与AMQP服务器的交互来实现自身的逻辑。例如在RabbitMQ中,客户端可以通过publish命令发送消息,txSelect开启一个事务,txCommit提交一个事务。 在了解了AMQP模型以后,需要简单介绍一下AMQP的协议栈,AMQP协议本身包括三层: 1.Module Layer,位于协议最高层,主要定义了一些供客户端调用的命令,客户端可以利用这些命令实现自己的业务逻辑,例如,客户端可以通过queue.declare声明一个队列,利用consume命令获取一个队列中的消息。 2.Session Layer,主要负责将客户端的命令发送给服务器,在将服务器端的应答返回给客户端,主要为客户端与服务器之间通信提供可靠性、同步机制和错误处理。 3.Transport Layer,主要传输二进制数据流,提供帧的处理、信道复用、错误检测和数据表示。 RabbitMQ使用场景 学习RabbitMQ的使用场景,来自官方教程:https://www.rabbitmq.com/getstarted.html 场景1:单发送单接收 使用场景:简单的发送与接收,没有特别的处理。 Producer:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import com.rabbitmq.client.ConnectionFactory; import com.rabbitmq.client.Connection; import com.rabbitmq.client.Channel; public class Send { private final static String QUEUE_NAME = "hello"; public static void main(String[] argv) throws Exception { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(QUEUE_NAME, false, false, false, null); String message = "Hello World!"; channel.basicPublish("", QUEUE_NAME, null, message.getBytes()); System.out.println(" [x] Sent '" + message + "'"); channel.close(); connection.close(); } } |
Consumer:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
import com.rabbitmq.client.ConnectionFactory; import com.rabbitmq.client.Connection; import com.rabbitmq.client.Channel; import com.rabbitmq.client.QueueingConsumer; public class Recv { private final static String QUEUE_NAME = "hello"; public static void main(String[] argv) throws Exception { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(QUEUE_NAME, false, false, false, null); System.out.println(" [*] Waiting for messages. To exit press CTRL+C"); QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume(QUEUE_NAME, true, consumer); while (true) { QueueingConsumer.Delivery delivery = consumer.nextDelivery(); String message = new String(delivery.getBody()); System.out.println(" [x] Received '" + message + "'"); } } } |
场景2:单发送多接收 使用场景:一个发送端,多个接收端,如分布式的任务派发。为了保证消息发送的可靠性,不丢失消息,使消息持久化了。同时为了防止接收端在处理消息时down掉,只有在消息处理完成后才发送ack消息。 Producer:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
import com.rabbitmq.client.ConnectionFactory; import com.rabbitmq.client.Connection; import com.rabbitmq.client.Channel; import com.rabbitmq.client.MessageProperties; public class NewTask { private static final String TASK_QUEUE_NAME = "task_queue"; public static void main(String[] argv) throws Exception { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null); String message = getMessage(argv); channel.basicPublish( "", TASK_QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes()); System.out.println(" [x] Sent '" + message + "'"); channel.close(); connection.close(); } private static String getMessage(String[] strings){ if (strings.length < 1) return "Hello World!"; return joinStrings(strings, " "); } private static String joinStrings(String[] strings, String delimiter) { int length = strings.length; if (length == 0) return ""; StringBuilder words = new StringBuilder(strings[0]); for (int i = 1; i < length; i++) { words.append(delimiter).append(strings[i]); } return words.toString(); } } |
发送端和场景1不同点: 1、使用“task_queue”声明了另一个Queue,因为RabbitMQ不容许声明2个相同名称、配置不同的Queue 2、使"task_queue"的Queue的durable的属性为true,即使消息队列durable 3、使用MessageProperties.PERSISTENT_TEXT_PLAIN使消息durable When RabbitMQ quits or crashes it will forget the queues and messages unless you tell it not to. Two things are required to make sure that messages aren’t lost: we need to mark both the queue […]
View Details上次我们介绍了在单机、集群下高并发场景可以选择的一些方案,传送门:高并发场景之一般解决方案 但是也发现了一些问题,比如集群下使用ConcurrentQueue或加锁都不能解决问题,后来采用Redis队列也不能完全解决问题, 因为使用Redis要自己实现分布式锁 这次我们来了解一下一个专门处理队列的组件:RabbitMQ,这个东西天生支持分布式队列。 下面我们来用RabbitMQ来实现上一篇的场景 一、新建RabbitMQ.Receive
|
1 2 |
private static ConnectionFactory factory = new ConnectionFactory { HostName = "192.168.1.109", UserName = "ljr", Password = "root", VirtualHost = "/" }; |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
1 static void Main(string[] args) 2 { 3 using (var connection = factory.CreateConnection()) 4 { 5 using (var channel = connection.CreateModel()) 6 { 7 var consumer = new EventingBasicConsumer(); 8 consumer.Received += (model, ea) => 9 { 10 var body = ea.Body; 11 var message = Encoding.UTF8.GetString(body); 12 Console.WriteLine(" [x] Received {0}", message); 13 14 var total = DbHelper.ExecuteScalar("Select Total from ConCurrency where Id = 1", null).ToString(); 15 var value = int.Parse(total) + 1; 16 17 DbHelper.ExecuteNonQuery(string.Format("Update ConCurrency Set Total = {0} where Id = 1", value.ToString()), null); 18 }; 19 20 channel.QueueDeclare(queue: "queueName", durable: false, exclusive: false, autoDelete: false, arguments: null); 21 channel.BasicConsume(queue: "queueName", noAck: true, consumer: consumer); 22 23 Console.WriteLine(" Press [enter] to exit."); 24 Console.ReadLine(); 25 } 26 } 27 } |
二、新建RabbitMQ.Send
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
1 static void Main(string[] args) 2 { 3 for (int i = 1; i <= 500; i++) 4 { 5 Task.Run(async () => 6 { 7 await Produce(); 8 }); 9 10 Console.WriteLine(i); 11 } 12 13 Console.ReadKey(); 14 } 15 16 public static Task Produce() 17 { 18 return Task.Factory.StartNew(() => 19 { 20 using (var connection = factory.CreateConnection()) 21 { 22 using (var channel = connection.CreateModel()) 23 { 24 var body = Encoding.UTF8.GetBytes(Guid.NewGuid().ToString()); 25 channel.QueueDeclare(queue: "queueName", durable: false, exclusive: false, autoDelete: false, arguments: null); 26 channel.BasicPublish(exchange: "", routingKey: "queueName", basicProperties: null, body: body); 27 } 28 } 29 }); 30 } |
这里是模拟500个用户请求,正常的话最后Total就等于500 我们来说试试看,运行程序 2.1、打开接收端 2.2 运行客户端 2.3、可以看到2边几乎是实时的,再去看看数据库 三、我们在集群里执行 最后数据是1000 完全没有冲突,好了,就是这样 。 from: https://www.cnblogs.com/lanxiaoke/p/6659548.html
View DetailsAdd the dotnet product feed Before installing .NET, you’ll need to register the Microsoft key, register the product repository, and install required dependencies. This only needs to be done once per machine. Open a terminal and run the following commands:
|
1 |
sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm |
Install the .NET Runtime Update the products available for installation, then install the .NET Runtime. In your terminal, run the following commands:
|
1 2 3 4 |
sudo yum update sudo yum install aspnetcore-runtime-2.2 也可以安装SDK yum install dotnet-sdk-2.2 |
The previous command will install the .NET Core Runtime Bundle, which includes the .NET Core runtime and the ASP.NET Core runtime. To […]
View DetailsRedis服务器设置密码后,使用service redis stop 会出现以下信息: service redis stop Stopping … OK (error) NOAUTH Authentication required. Waiting for Redis to shutdown … Waiting for Redis to shutdown … Waiting for Redis to shutdown … Waiting for Redis to shutdown … Waiting for Redis to shutdown … Waiting for Redis to shutdown … Waiting for Redis to shutdown … Waiting for Redis to shutdown … 出现这样的错误信息,redis 这时是没有停止服务的。可以使用ps -ef | grep redis 查进程号 然后kill 掉,如果在deamon下还需要去删除pid文件,有点繁琐。 解决办法: 用redis-cli 密码登陆(redis-cli -a password)就OK了。 再用ps -ef | grep redis 可以看到redis进程已经正常退出。 修改redis服务脚本,加入如下所示的红色授权信息即可: vi /etc/init.d/redis $CLIEXEC -a "password" -p $REDISPORT shutdown from:https://www.cnblogs.com/jeffen/p/6068745.html
View Details一、安装redis 第一步:下载redis安装包 wget http://download.redis.io/releases/redis-4.0.6.tar.gz
|
1 2 3 4 5 6 7 8 9 10 11 |
[root@iZwz991stxdwj560bfmadtZ local]# wget http://download.redis.io/releases/redis-4.0.6.tar.gz --2017-12-13 12:35:12-- http://download.redis.io/releases/redis-4.0.6.tar.gz Resolving download.redis.io (download.redis.io)... 109.74.203.151 Connecting to download.redis.io (download.redis.io)|109.74.203.151|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 1723533 (1.6M) [application/x-gzip] Saving to: ‘redis-4.0.6.tar.gz’ 100%[==========================================================================================================>] 1,723,533 608KB/s in 2.8s 2017-12-13 12:35:15 (608 KB/s) - ‘redis-4.0.6.tar.gz’ saved [1723533/1723533] |
第二步:解压压缩包 tar -zxvf redis-4.0.6.tar.gz
|
1 |
[root@iZwz991stxdwj560bfmadtZ local]# tar -zxvf redis-4.0.6.tar.gz |
第三步:yum安装gcc依赖 yum install gcc
|
1 |
[root@iZwz991stxdwj560bfmadtZ local]# yum install gcc |
遇到选择,输入y即可 第四步:跳转到redis解压目录下 cd redis-4.0.6
|
1 |
[root@iZwz991stxdwj560bfmadtZ local]# cd redis-4.0.6 |
第五步:编译安装 make MALLOC=libc
|
1 |
[root@iZwz991stxdwj560bfmadtZ redis-4.0.6]# make MALLOC=libc |
将/usr/local/redis-4.0.6/src目录下的文件加到/usr/local/bin目录 cd src && make install
|
1 2 3 4 5 6 7 8 9 10 |
[root@iZwz991stxdwj560bfmadtZ redis-4.0.6]# cd src && make install CC Makefile.dep Hint: It's a good idea to run 'make test' ;) INSTALL install INSTALL install INSTALL install INSTALL install INSTALL install |
二、启动redis的三种方式 先切换到redis src目录下
|
1 |
[root@iZwz991stxdwj560bfmadtZ redis-4.0.6]# cd src |
1、直接启动redis ./redis-server
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
[root@iZwz991stxdwj560bfmadtZ src]# ./redis-server 18685:C 13 Dec 12:56:12.507 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 18685:C 13 Dec 12:56:12.507 # Redis version=4.0.6, bits=64, commit=00000000, modified=0, pid=18685, just started 18685:C 13 Dec 12:56:12.507 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 4.0.6 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 18685 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' 18685:M 13 Dec 12:56:12.508 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. 18685:M 13 Dec 12:56:12.508 # Server initialized 18685:M 13 Dec 12:56:12.508 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect. 18685:M 13 Dec 12:56:12.508 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled. 18685:M 13 Dec 12:56:12.508 * Ready to accept connections |
如上图:redis启动成功,但是这种启动方式需要一直打开窗口,不能进行其他操作,不太方便。 按 ctrl + c可以关闭窗口。 2、以后台进程方式启动redis 第一步:修改redis.conf文件 将
|
1 |
daemonize no |
修改为
|
1 |
daemonize yes |
第二步:指定redis.conf文件启动 1 ./redis-server /usr/local/redis-4.0.6/redis.conf
|
1 2 3 4 |
[root@iZwz991stxdwj560bfmadtZ src]# ./redis-server /usr/local/redis-4.0.6/redis.conf 18713:C 13 Dec 13:07:41.109 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 18713:C 13 Dec 13:07:41.109 # Redis version=4.0.6, bits=64, commit=00000000, modified=0, pid=18713, just started 18713:C 13 Dec 13:07:41.109 # Configuration loaded |
第三步:关闭redis进程 首先使用ps -aux | grep redis查看redis进程
|
1 2 3 |
[root@iZwz991stxdwj560bfmadtZ src]# ps -aux | grep redis root 18714 0.0 0.1 141752 2008 ? Ssl 13:07 0:00 ./redis-server 127.0.0.1:6379 root 18719 0.0 0.0 112644 968 pts/0 R+ 13:09 0:00 grep --color=auto redis |
使用kill命令杀死进程
|
1 |
[root@iZwz991stxdwj560bfmadtZ src]# kill -9 18714 |
3、设置redis开机自启动 1、在/etc目录下新建redis目录 mkdir redis
|
1 |
[root@iZwz991stxdwj560bfmadtZ etc]# mkdir redis |
2、将/usr/local/redis-4.0.6/redis.conf 文件复制一份到/etc/redis目录下,并命名为6379.conf
|
1 |
[root@iZwz991stxdwj560bfmadtZ redis]# cp /usr/local/redis-4.0.6/redis.conf /etc/redis/6379.conf |
[…]
View Detailsgit remote set-url命令修改remote URL git remote set-url传递两个参数 remote name。例如,origin或者upstream new remote url。例如,git@github.com:USERNAME/OTHERREPOSITORY.git 例如:从SSH切换到HTTPS的远程URL 打开终端 切换到你项目的工作目录 列出remotes,是为了得到你想要改变的remote的名字
|
1 2 3 |
xxxxxx@xxxxxx:~/workspace/goal$ git remote -v origin git@github.com:xxxxxx/SpringBoot.git (fetch) origin git@github.com:xxxxxx/SpringBoot.git (push) |
使用git remote set-url命令从SSH到HTTPS的远程URL
|
1 |
xxxxxx@xxxxxx:~/workspace/goal$ git remote set-url origin https://github.com/xxxxxx/SpringBoot.git |
验证是否改变成功
|
1 2 3 |
xxxxxx@xxxxxx:~/workspace/goal$ git remote -v origin https://github.com:xxxxxx/SpringBoot.git (fetch) origin https://github.com:xxxxxx/SpringBoot.git (push) |
from:https://www.cnblogs.com/yandufeng/p/6423821.html
View Details问题: 1、创建maven项目的时候,jdk版本是1.5版本,而自己安装的是1.7或者1.8版本。 2、每次右键项目名-maven->update project 时候,项目jdk版本变了,变回1.5版本或者其他版本 解决办法: 解决办法一:在项目中的pom.xml指定jdk版本,如下:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build> |
这个方法只能保证该项目是jdk1.8版本,每次新建项目都得加上面代码,不推荐使用,推荐第二种方法。 解决方法二:在maven的安装目录找到settings.xml文件,在里面添加如下代码
|
1 2 3 4 5 6 7 8 9 10 11 12 |
<profile> <id>jdk-1.8</id> <activation> <activeByDefault>true</activeByDefault> <jdk>1.8</jdk> </activation> <properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion> </properties> </profile> |
添加完后,在对eclipse进行设置。window->preferences->maven->user settings,user settings那里选择maven安装目录下的settings.xml文件。如下图 设置完成后,右键项目->maven->update project,这样每次新建maven项目都默认为jdk1.8版本了 解决方法三: 在解决方法二中,user settings的默认settigs.xml文件路径为:c:\users\Hxinguan\.m2\settings.xml,如下图。只要把设置好的settings.xml文件复制到该目录下,然后update project就好了。 from:https://www.cnblogs.com/Hxinguan/p/6132446.html
View Details错误描述 当创建有动态web模块3.0支持的项目时,需要用到Java版本不低于1.6。 在Markers标签页中显示的错误为:Dynamic Web Module 3.0 requires Java 1.6 or newer. 如图所示: 解决方法 注:有的时候1、2、3已经实现,直接跳过,操作4就OK了。 1、首先在Eclipse中安装JRE,Preferences > Java > Installed JREs,点击 Add,并添加自己的Java路径。 2、确认编译器版本不低于1.6,右键项目 > Properties > Java Compiler,保证“Compiler compliance level”不低于1.6。 3、保证项目的Facet中Java版本不低于1.6,右键项目 > Properties > MyEclipse > Project Facets > Java,保证“Java”不低于1.6。 4、在项目的pom.xml的标签中加入:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> </plugins> </build> |
5、最后一步,右键项目 > Maven > Update Project。 from:https://blog.csdn.net/liuxinghao/article/details/37088063
View Details需要设置的几处地方为: Window->Preferences->General->Workspace 面板Text file encoding 选择UTF-8 Window->Preferences->General ->Content Types->Text->JSP 最下面设置为UTF-8 Window->Preferences->Web->JSP Files 面板选择 ISO 10646/Unicode(UTF-8) 下面的图给出了具体的操作步骤: 第一步: 第二步: 当然还可以修改Java Source File、XML、Java Properties File等,在下面的Default encoding输入框中输入UTF-8,并点Update生效 如下图所示: 第三步: 通过上面的几个步骤,就可以完成设置编码,方便开发使用了。 from:https://blog.csdn.net/w_y_l_/article/details/82697503
View Detailssysbench是一个压力测试工具、可以用它来测试cpu、mem、disk、thread、mysql、postgr、oracle;然而作为一个mysql dba 我当然是用它来压测mysql啦! 一、从哪里可以下载到sysbench: sysbench的源码可以在github上面下载的到,sysbench的主页
|
1 |
https://github.com/akopytov/sysbench |
二、sysbench的一些安装依赖:
|
1 |
yum -y install make automake libtool pkgconfig libaio-devel vim-common |
在我的机器上已经安装上了mysql相关的所有包,如果你机器上还没有安装过这些,那你还要安装上mysql的开发包,由于系统自带mariadb 这个mysql分支,所以在安装mysql-devel时应该是安装mariadb-devel 三、安装sysbench: 1 进入到sysbench源码目录
|
1 |
/home/jianglexing/Desktop/sysbench-master |
2 执行autogen.sh用它来生成configure这个文件
|
1 |
./autogen.sh |
3 执行configure && make && make install 来完成sysbench的安装
|
1 2 3 |
./configure --prefix=/usr/local/sysbench/ --with-mysql --with-mysql-includes=/usr/local/mysql/include --with-mysql-libs=/usr/local/mysql/lib make make install |
我这里之所以要这样写是因为我的mysql安装在/usr/local/;而不是默认的rpm的安装位置 四、测试是否安装成功:
|
1 2 |
[root@workstudio bin]# /usr/local/sysbench/bin/sysbench --version sysbench 1.1.0 |
到目前为止sysbench的安装就算是完成了! 五、sysbench的帮助内容如下:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
1 Usage: 2 sysbench [options]... [testname] [command] 3 4 Commands implemented by most tests: prepare run cleanup help 5 6 General options: 7 --threads=N number of threads to use [1] 8 --events=N limit for total number of events [0] 9 --time=N limit for total execution time in seconds [10] 10 --warmup-time=N execute events for this many seconds with statistics disabled before the actual benchmark run with statistics enabled [0] 11 --forced-shutdown=STRING number of seconds to wait after the --time limit before forcing shutdown, or 'off' to disable [off] 12 --thread-stack-size=SIZE size of stack per thread [64K] 13 --thread-init-timeout=N wait time in seconds for worker threads to initialize [30] 14 --rate=N average transactions rate. 0 for unlimited rate [0] 15 --report-interval=N periodically report intermediate statistics with a specified interval in seconds. 0 disables intermediate reports [0] 16 --report-checkpoints=[LIST,...] dump full statistics and reset all counters at specified points in time. The argument is a list of comma-separated values representing the amount of time in seconds elapsed from start of test when report checkpoint(s) must be performed. Report checkpoints are off by default. [] 17 --debug[=on|off] print more debugging info [off] 18 --validate[=on|off] perform validation checks where possible [off] 19 --help[=on|off] print help and exit [off] 20 --version[=on|off] print version and exit [off] 21 --config-file=FILENAME File containing command line options 22 --luajit-cmd=STRING perform LuaJIT control command. This option is equivalent to 'luajit -j'. See LuaJIT documentation for more information 23 --tx-rate=N deprecated alias for --rate [0] 24 --max-requests=N deprecated alias for --events [0] 25 --max-time=N deprecated alias for --time [0] 26 --num-threads=N deprecated alias for --threads [1] 27 28 Pseudo-Random Numbers Generator options: 29 --rand-type=STRING random numbers distribution {uniform,gaussian,special,pareto} [special] 30 --rand-spec-iter=N number of iterations used for numbers generation [12] 31 --rand-spec-pct=N percentage of values to be treated as 'special' (for special distribution) [1] 32 --rand-spec-res=N percentage of 'special' values to use (for special distribution) [75] 33 --rand-seed=N seed for random number generator. When 0, the current time is used as a RNG seed. [0] 34 --rand-pareto-h=N parameter h for pareto distribution [0.2] 35 36 Log options: 37 --verbosity=N verbosity level {5 - debug, 0 - only critical messages} [3] 38 39 --percentile=N percentile to calculate in latency statistics (1-100). Use the special value of 0 to disable percentile calculations [95] 40 --histogram[=on|off] print latency histogram in report [off] 41 42 General database options: 43 44 --db-driver=STRING specifies database driver to use ('help' to get list of available drivers) 45 --db-ps-mode=STRING prepared statements usage mode {auto, disable} [auto] 46 --db-debug[=on|off] print database-specific debug information [off] 47 48 49 Compiled-in database drivers: 50 mysql - MySQL driver 51 52 mysql options: 53 --mysql-host=[LIST,...] MySQL server host [localhost] 54 --mysql-port=[LIST,...] MySQL server port [3306] 55 --mysql-socket=[LIST,...] MySQL socket 56 --mysql-user=STRING MySQL user [sbtest] 57 --mysql-password=STRING MySQL password [] 58 --mysql-db=STRING MySQL database name [sbtest] 59 --mysql-ssl[=on|off] use SSL connections, if available in the client library [off] 60 --mysql-ssl-cipher=STRING use specific cipher for SSL connections [] 61 --mysql-compression[=on|off] use compression, if available in the client library [off] 62 --mysql-debug[=on|off] trace all client library calls [off] 63 --mysql-ignore-errors=[LIST,...] list of errors to ignore, or "all" [1213,1020,1205] 64 --mysql-dry-run[=on|off] Dry run, pretend that all MySQL client API calls are successful without executing them [off] 65 66 Compiled-in tests: 67 fileio - File I/O test 68 cpu - CPU performance test 69 memory - Memory functions speed test 70 threads - Threads subsystem performance test 71 mutex - Mutex performance test 72 73 See 'sysbench <testname> help' for a list of options for each test. |
六、sysbench对数据库进行压力测试的过程: 1 prepare 阶段 这个阶段是用来做准备的、比较说建立好测试用的表、并向表中填充数据。 2 run 阶段 这个阶段是才是去跑压力测试的SQL 3 cleanup 阶段 这个阶段是去清除数据的、也就是prepare阶段初始化好的表要都drop掉 七、sysbench 中的测试类型大致可以分成内置的,lua脚本自定义的测试: 1、内置: fileio 、cpu 、memory 、threads 、 mutex 2、lua脚本自定义型: sysbench 自身内涵了一些测试脚本放在了安装目录下的:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
[jianglexing@cstudio sysbench]$ ll share/sysbench 总用量 60 -rwxr-xr-x. 1 root root 1452 10月 17 15:18 bulk_insert.lua -rw-r--r--. 1 root root 13918 10月 17 15:18 oltp_common.lua -rwxr-xr-x. 1 root root 1290 10月 17 15:18 oltp_delete.lua -rwxr-xr-x. 1 root root 2415 10月 17 15:18 oltp_insert.lua -rwxr-xr-x. 1 root root 1265 10月 17 15:18 oltp_point_select.lua -rwxr-xr-x. 1 root root 1649 10月 17 15:18 oltp_read_only.lua -rwxr-xr-x. 1 root root 1824 10月 17 15:18 oltp_read_write.lua -rwxr-xr-x. 1 root root 1118 10月 17 15:18 oltp_update_index.lua -rwxr-xr-x. 1 root root 1127 10月 17 15:18 oltp_update_non_index.lua -rwxr-xr-x. 1 root root 1440 10月 17 15:18 oltp_write_only.lua -rwxr-xr-x. 1 root root 1919 10月 17 15:18 select_random_points.lua -rwxr-xr-x. 1 root root 2118 10月 17 15:18 select_random_ranges.lua drwxr-xr-x. 4 root root 46 10月 17 15:18 tests |
八、通过sysbench自带的lua脚本对mysql进行测试: 1、第一步 prepare
|
1 2 |
sysbench --mysql-host=localhost --mysql-port=3306 --mysql-user=sbtest \ --mysql-password=123456 --mysql-db=tempdb oltp_insert prepare |
2、第二步 run
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
sysbench --mysql-host=localhost --mysql-port=3306 --mysql-user=sbtest --mysql-password=123456 --mysql-db=tempdb oltp_insert run sysbench 1.1.0 (using bundled LuaJIT 2.1.0-beta3) Running the test with following options: Number of threads: 1 Initializing random number generator from current time Initializing worker threads... Threads started! SQL statistics: queries performed: read: 0 write: 22545 other: 0 total: 22545 transactions: 22545 (2254.37 per sec.) queries: 22545 (2254.37 per sec.) ignored errors: 0 (0.00 per sec.) reconnects: 0 (0.00 per sec.) Throughput: events/s (eps): 2254.3691 time elapsed: 10.0006s total number of events: 22545 Latency (ms): min: 0.31 avg: 0.44 max: 10.47 95th percentile: 0.67 sum: 9918.59 Threads fairness: events (avg/stddev): 22545.0000/0.00 execution time (avg/stddev): 9.9186/0.00 |
3、第三步 cleanup
|
1 2 3 4 |
sysbench --mysql-host=localhost --mysql-port=3306 --mysql-user=sbtest --mysql-password=123456 --mysql-db=tempdb oltp_insert cleanup sysbench 1.1.0 (using bundled LuaJIT 2.1.0-beta3) Dropping table 'sbtest1'... |
from:https://www.cnblogs.com/JiangLe/p/7059136.html
View Details