<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MySQL Preacher &#187; mysqlslap</title>
	<atom:link href="http://mysqlpreacher.com/wordpress/tag/mysqlslap/feed/" rel="self" type="application/rss+xml" />
	<link>http://mysqlpreacher.com/wordpress</link>
	<description>A MySQL blog, from a MySQL DBA</description>
	<lastBuildDate>Wed, 16 Jun 2010 13:13:15 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Slap&#8217;em</title>
		<link>http://mysqlpreacher.com/wordpress/2009/02/slapem/</link>
		<comments>http://mysqlpreacher.com/wordpress/2009/02/slapem/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 13:37:49 +0000</pubDate>
		<dc:creator>Darren Cassar</dc:creator>
				<category><![CDATA[Beginner]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[benchmarking]]></category>
		<category><![CDATA[monitoring]]></category>
		<category><![CDATA[mysqlslap]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://mysqlpreacher.com/wordpress/?p=80</guid>
		<description><![CDATA[Giving a bunch of mysql instances something you do everyday and you might think &#8230;.. how should I do it? Write a bunch of selects and inserts manually? nahh that takes s**tload of time, should I run binlogs collected from a live system on my test server? nahh thats not practical nor is it real [...]]]></description>
			<content:encoded><![CDATA[<p>Giving a bunch of mysql instances something you do everyday and you might think &#8230;.. how should I do it? Write a bunch of selects and inserts manually? nahh that takes s**tload of time, should I run binlogs collected from a live system on my test server? nahh thats not practical nor is it real since it doesn&#8217;t contain selects, should I gather the general query log and try that out? nahhh  &#8230;..</p>
<p>MySQL has been kind enough to supply us with their mysql_slap which does the job for us and given I needed to do a proof of concept on monitoring a group of 4 circular replicated servers I wrote a small script which does the job of slapping them with a varying level of concurrancy, iterations, number of queries and connections for as long as you like.</p>
<p>Here it is and I hope some of you might find it useful for slapping their own test servers :).</p>
<blockquote><p><code>#!/bin/bash</code></p>
<p><code>NumberOfConcurrentLoads=4</code><br />
<code>LOGFILE=randomslap-4n-circularreplication</code></p>
<p><code>load () {</code></p>
<p><code> run=0</code><br />
<code> #Obtaining pid of the current process</code><br />
<code> PID=$$</code></p>
<p><code> echo "MySQL Slap random loading MySQL instances" &gt;&gt; $LOGFILE-$PID.log</code><br />
<code> echo "Loading child $a out of $NumberOfConcurrentLoads"  &gt;&gt; $LOGFILE-$PID.log</code><br />
<code> echo "Starting at: `date`" &gt;&gt; $LOGFILE-$PID.log</code><br />
<code> echo ""</code></p>
<p><code> while [ 1 ]</code><br />
<code> do</code></p>
<p><code> #Generate a few values for the actual command to run through</code><br />
<code> prt=$((RANDOM%4+17001))  #ports being 17001,17002,17003,17004</code><br />
<code> cnc=$((RANDOM%50+1))     #number of concurrent sessions</code><br />
<code> itr=$((RANDOM%9+1))      #number of iterations</code><br />
<code> noq=$((RANDOM%100+50))   #number of queries</code><br />
<code> sec=$((RANDOM%30+10))    #seconds idle after finishing the process</code></p>
<p><code> echo "Run number $run" &gt;&gt; $LOGFILE-$PID.log</code><br />
<code> echo `date +%Y/%m/%d---%H:%M | sed 's/---/  /'` &gt;&gt; $LOGFILE-$PID.log</code></p>
<p><code> echo "Port=$prt" &gt;&gt; $LOGFILE-$PID.log</code><br />
<code> echo "Concurrency=$cnc" &gt;&gt; $LOGFILE-$PID.log</code><br />
<code> echo "Iterations=$itr" &gt;&gt; $LOGFILE-$PID.log</code><br />
<code> echo "Number-Of-Queries=$noq" &gt;&gt; $LOGFILE-$PID.log</code><br />
<code> echo "Breaktime=$sec" &gt;&gt; $LOGFILE-$PID.log</code></p>
<p><code> echo "Output:" &gt;&gt; $LOGFILE-$PID.log</code><br />
<code> mysqlslap --user=root --password='msandbox' --auto-generate-sql -vv -h hostname -P $prt --concurrency=$cnc --iterations=$itr --number-of-queries=$noq &gt;&gt; $LOGFILE-$PID.log</code></p>
<p><code> run=`expr $run + 1`</code><br />
<code> sleep $sec</code></p>
<p><code> done</code></p>
<p><code>}</code><br />
<code>#Fork a number of concurrent scripts to emulate more of a realistic load rather than one process connecting to just one server at a time</code><br />
<code>for ((a=1;a&lt;=NumberOfConcurrentLoads;a++))</code><br />
<code>do</code><br />
<code> load &amp;</code><br />
<code>done</code></p></blockquote>
<p>If you are wondering &#8230; yes I totally indendate my code :) but the html version came out this way and I didn&#8217;t bother with indenting it using html really.</p>
]]></content:encoded>
			<wfw:commentRss>http://mysqlpreacher.com/wordpress/2009/02/slapem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
