Amoeba for mysql安装与测试(转载)

Amoeba for mysql安装与测试

前提条件:
8G内存 16核CPU,一主库一从库
mysql 5.0 icc编译版
测试工具 mysqlslap

1.安装amoeba

装一下jdk
wget http://download.oracle.com/otn-pub/java/jdk/6u25-b06/jdk-6u25-linux-i586-rpm.bin
chmod +x jdk-6u25-linux-i586-rpm.bin
./ jdk-6u20-linux-i586-rpm.bin

vi /etc/profile
export JAVA_HOME=/usr/java/jdk1.6.0_25
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
source /etc/profile

amoeba从网上下载,直接用
mkdir /usr/local/amoeba/
cd /usr/local/amoeba/
wget http://blogimg.chinaunix.net/blog/upfile2/101027160252.zip
unzip 101027160252.zip
chmod -R +x /usr/local/amoeba/bin/

2. 配置amoeba
amoeba.xml配置(出自网络有名的一篇测试文章)

<?xml version=”1.0″ encoding=”gbk”?>

<!DOCTYPE amoeba:configuration SYSTEM “amoeba.dtd”>
<amoeba:configuration xmlns:amoeba=”http://amoeba.meidusa.com/”>

<server>
<!– proxy server绑定的端口 –>
<property name=”port”>8066</property>

<!– proxy server绑定的IP –>
<property name=”ipAddress”>127.0.0.1</property>
<!– proxy server net IO Read thread size –>
<property name=”readThreadPoolSize”>20</property>

<!– proxy server client process thread size –>
<property name=”clientSideThreadPoolSize”>30</property>

<!– mysql server data packet process thread size –>
<property name=”serverSideThreadPoolSize”>30</property>

<!– socket Send and receive BufferSize(unit:K)  –>
<property name=”netBufferSize”>128</property>

<!– Enable/disable TCP_NODELAY (disable/enable Nagle’s algorithm). –>
<property name=”tcpNoDelay”>true</property>

<!– 对外验证的用户名 –>
<property name=”user”>root</property>

<!– 对外验证的密码 –>
<property name=”password”>amopassword</property>

<!– query timeout( default: 60 second , TimeUnit:second) –>
<property name=”queryTimeout”>60</property>
</server>

<!–
每个ConnectionManager都将作为一个线程启动。
manager负责Connection IO读写/死亡检测
–>
<connectionManagerList>
<connectionManager name=”defaultManager” class=”com.meidusa.amoeba.net.MultiConnectionManagerWrapper”>
<property name=”subManagerClassName”>com.meidusa.amoeba.net.AuthingableConnectionManager</property>

<!–
default value is avaliable Processors
<property name=”processors”>5</property>
–>
</connectionManager>
</connectionManagerList>

<dbServerList>
<!–
一台mysqlServer 需要配置一个pool,
如果多台 平等的mysql需要进行loadBalance,
平台已经提供一个具有负载均衡能力的objectPool:com.meidusa.amoeba.mysql.server.MultipleServerPool
简单的配置是属性加上 virtual=”true”,该Pool 不允许配置factoryConfig
或者自己写一个ObjectPool。
–>
<dbServer name=”server1″>

<!– PoolableObjectFactory实现类 –>
<factoryConfig class=”com.meidusa.amoeba.mysql.net.MysqlServerConnectionFactory”>
<property name=”manager”>defaultManager</property>

<!– 真实mysql数据库端口 –>
<property name=”port”>3306</property>

<!– 真实mysql数据库IP –>
<property name=”ipAddress”>127.0.0.1</property>
<property name=”schema”>test</property>

<!– 用于登陆mysql的用户名 –>
<property name=”user”>root</property>

<!– 用于登陆mysql的密码 –>

<property name=”password”>password</property>

</factoryConfig>

<!– ObjectPool实现类 –>
<poolConfig class=”com.meidusa.amoeba.net.poolable.PoolableObjectPool”>
<property name=”maxActive”>200</property>
<property name=”maxIdle”>200</property>
<property name=”minIdle”>10</property>
<property name=”minEvictableIdleTimeMillis”>600000</property>
<property name=”timeBetweenEvictionRunsMillis”>600000</property>
<property name=”testOnBorrow”>true</property>
<property name=”testWhileIdle”>true</property>
</poolConfig>
</dbServer>

<dbServer name=”server2″>

<!– PoolableObjectFactory实现类 –>
<factoryConfig class=”com.meidusa.amoeba.mysql.net.MysqlServerConnectionFactory”>
<property name=”manager”>defaultManager</property>

<!– 真实mysql数据库端口 –>
<property name=”port”>3308</property>

<!– 真实mysql数据库IP –>
<property name=”ipAddress”>127.0.0.1</property>
<property name=”schema”>test</property>

<!– 用于登陆mysql的用户名 –>
<property name=”user”>root</property>

<!– 用于登陆mysql的密码 –>

<property name=”password”>password</property>

</factoryConfig>

<!– ObjectPool实现类 –>
<poolConfig class=”com.meidusa.amoeba.net.poolable.PoolableObjectPool”>
<property name=”maxActive”>200</property>
<property name=”maxIdle”>200</property>
<property name=”minIdle”>10</property>
<property name=”minEvictableIdleTimeMillis”>600000</property>
<property name=”timeBetweenEvictionRunsMillis”>600000</property>
<property name=”testOnBorrow”>true</property>
<property name=”testWhileIdle”>true</property>
</poolConfig>
</dbServer>

<dbServer name=”master” virtual=”true”>
<poolConfig class=”com.meidusa.amoeba.server.MultipleServerPool”>
<!– 负载均衡参数 1=ROUNDROBIN , 2=WEIGHTBASED , 3=HA–>
<property name=”loadbalance”>1</property>

<!– 参与该pool负载均衡的poolName列表以逗号分割 –>
<property name=”poolNames”>server1</property>
</poolConfig>
</dbServer>

<dbServer name=”slave” virtual=”true”>
<poolConfig class=”com.meidusa.amoeba.server.MultipleServerPool”>
<!– 负载均衡参数 1=ROUNDROBIN , 2=WEIGHTBASED , 3=HA–>
<property name=”loadbalance”>1</property>

<!– 参与该pool负载均衡的poolName列表以逗号分割 –>
<property name=”poolNames”>server1,server2,server2</property>
</poolConfig>
</dbServer>

</dbServerList>

<queryRouter class=”com.meidusa.amoeba.mysql.parser.MysqlQueryRouter”>
<property name=”ruleConfig”>${amoeba.home}/conf/rule.xml</property>
<property name=”functionConfig”>${amoeba.home}/conf/functionMap.xml</property>
<property name=”ruleFunctionConfig”>${amoeba.home}/conf/ruleFunctionMap.xml</property>
<property name=”LRUMapSize”>1500</property>
<property name=”defaultPool”>master</property>

<property name=”writePool”>master</property>
<property name=”readPool”>slave</property>
<property name=”needParse”>true</property>
</queryRouter>
</amoeba:configuration>

3. 启动amoeba
/usr/local/amoeba/bin/amoeba &

4.在amoeba配置文件中,将读按1:2比例分配到主从,写分配到主.
别忘记了在master,slave添加相应的mysql访问权限

5.要确认amoeba转到哪个服务,停止slave同步进程,在主从建相同的表插入不同的数据.
然后通过amoeba去读取

实践证明:
读按1:2比例分配到主从,写分配到主.这个要求是满足了,并且1:2的比例非常精确.不管是1:3还是1:4.

amoeba进程的消耗:
amoeba以java虚拟机启动,默认-server -Xms256m -Xmx256m -Xss128k
从进程启动开始,内存占用一直累加 达到256M*1.5物理内存,仍然未触发GC 直到重新启动进程
刚启动与启动一段时间相比,相同参数测试响应时间长一点.

内存与CPU充足的情况下:
mysqlslap -uroot -pamopassword -h127.0.0.1 -P8806 –concurrency=700 –number-of-queries=50000
–engine=myisam –debug-info –create-schema=test –auto-generate-sql –auto-generate-sql-load-type=write
–auto-generate-sql-add-autoincrement –auto-generate-sql -x 3 -y 4 –auto-generate-sql-secondary-indexes=1

并发数 总查询数 engine type 响应时间 资源消耗
700 50000 myisam write 4.48s 376M/200% CPU
700 50000 myisam read 4.43s 376M/500%~800%CPU
write期间CPU占用也比较高.innodb引擎的测试响应时间慢 3~4倍

如果将java启动参数 256M 改成1G
查询的响应时间没有加快, 但内存占用加大,CPU使用率减少.

当然mysqlslap生成的表和查询相对简单,不能和正式的生产环境相比,但此测试仍让我对amoeba有一定的了解.在选用时也有取舍的依据.

发表评论

电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>