<?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>domas mituzas &#187; gdb</title>
	<atom:link href="http://mituzas.lt/tag/gdb/feed/" rel="self" type="application/rss+xml" />
	<link>http://mituzas.lt</link>
	<description></description>
	<lastBuildDate>Fri, 30 Jul 2010 07:36:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1-alpha</generator>
		<item>
		<title>Read ahead&#8230;</title>
		<link>http://mituzas.lt/2010/01/02/read-ahead/</link>
		<comments>http://mituzas.lt/2010/01/02/read-ahead/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 11:00:43 +0000</pubDate>
		<dc:creator>Domas Mituzas</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[gdb]]></category>
		<category><![CDATA[innodb]]></category>

		<guid isPermaLink="false">http://mituzas.lt/?p=720</guid>
		<description><![CDATA[Mark wrote about how to find situations where InnoDB read-ahead is a bottleneck. What he didn&#8217;t disclose, though, is his trick to disable read-ahead without restart or recompile of MySQL. See, there&#8217;s no internal &#8220;disable read ahead knob&#8221;. But there &#8230; <a href="http://mituzas.lt/2010/01/02/read-ahead/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Mark <a href="http://www.facebook.com/notes/mysqlfacebook/when-doesnt-innodb-readahead-work/198536580932">wrote</a> about how to find situations where InnoDB read-ahead is a bottleneck. What he didn&#8217;t disclose, though, is his trick to disable read-ahead without restart or recompile of MySQL. See, there&#8217;s no internal &#8220;disable read ahead knob&#8221;. But there is&#8230;</p>
<pre>
buf_read_ahead_random(...){ ...
       if (srv_startup_is_before_trx_rollback_phase) {
                /* No read-ahead to avoid thread deadlocks */
                return(0);
        }
</pre>
<p>This variable is tested at two functions &#8211; buf_read_ahead_linear() and buf_read_ahead_random() and <b>nowhere else</b>. So yeah, &#8220;server startup is before transaction rollback phase&#8221; is another way of saying &#8220;don&#8217;t do read ahead, please please&#8221;. </p>
<pre>gdb -ex "set  srv_startup_is_before_trx_rollback_phase=1" \
    --batch -p $(pidof mysqld)</pre>
<p>And many servers bottlenecked on this became much much much faster (and 2000 concurrent threads running dropped to 10). Of course, this is most visible in high-latency-high-throughput I/O situations, but we&#8217;re hitting this contention spot on local disk setups too. </p>
<p>Don&#8217;t forget to have <a href='http://mituzas.lt/2009/12/29/when-bad-things-happen/'>the fix</a> if gdb decides to be nasty and locks up your server :)</p>
]]></content:encoded>
			<wfw:commentRss>http://mituzas.lt/2010/01/02/read-ahead/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>When bad things happen!</title>
		<link>http://mituzas.lt/2009/12/29/when-bad-things-happen/</link>
		<comments>http://mituzas.lt/2009/12/29/when-bad-things-happen/#comments</comments>
		<pubDate>Tue, 29 Dec 2009 16:25:23 +0000</pubDate>
		<dc:creator>Domas Mituzas</dc:creator>
				<category><![CDATA[misc]]></category>
		<category><![CDATA[gdb]]></category>

		<guid isPermaLink="false">http://mituzas.lt/?p=715</guid>
		<description><![CDATA[When bad things happen, like&#8230; &#8216;strace -f&#8217; or &#8216;gdb&#8217; or any other process inspection tool decides to hang your precious processes (they show up in state T in process lists), there&#8217;s always help: #include &#60;sys/ptrace.h&#62; #include &#60;signal.h&#62; main(int ac, char &#8230; <a href="http://mituzas.lt/2009/12/29/when-bad-things-happen/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When bad things happen, like&#8230; &#8216;strace -f&#8217; or &#8216;gdb&#8217; or any other process inspection tool decides to hang your precious processes (they show up in state T in process lists), there&#8217;s always help:</p>
<pre>
#include &lt;sys/ptrace.h&gt;
#include &lt;signal.h&gt;
main(int ac, char **av) {
int pid; if (ac&gt;1) pid=atoi(av[1]);
ptrace(PTRACE_ATTACH,pid,0,0);
ptrace(PTRACE_DETACH,pid,0,0);
kill(pid, SIGCONT); }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://mituzas.lt/2009/12/29/when-bad-things-happen/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>GDB 7!</title>
		<link>http://mituzas.lt/2009/10/08/gdb-7/</link>
		<comments>http://mituzas.lt/2009/10/08/gdb-7/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 20:30:39 +0000</pubDate>
		<dc:creator>Domas Mituzas</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[wikitech]]></category>
		<category><![CDATA[gdb]]></category>

		<guid isPermaLink="false">http://mituzas.lt/?p=630</guid>
		<description><![CDATA[I wasn&#8217;t prepared for this. After spending months playing with GDB development trees I somehow entirely missed that 7.0 release is getting close, and took me more than an hour to spot it. My favorite features are python scripting and &#8230; <a href="http://mituzas.lt/2009/10/08/gdb-7/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I wasn&#8217;t prepared for this. After spending months playing with GDB development trees I somehow entirely missed that <a href="http://www.gnu.org/software/gdb/download/ANNOUNCEMENT">7.0 release</a> is getting close, and took me more than an hour to spot it.</p>
<p>My favorite features are python scripting and non-stop debugging. I was toying around with python scripting for a while, and was planning to make backtraces make sense. Having hands that open means that one can see PHP backtraces, when gdb&#8217;ing apache, see table names and states when MySQL thread access handler interfaces, or remote IPs and users, when it is writing to network. Process inspection can simply rock, if right tools are created using these new capabilities, and I&#8217;m way too excited when I think about those. &#8220;Always have debugging symbols&#8221; gets way more meaning now.</p>
<p>Another issue I&#8217;ve been trying to resolve lately is avoiding long locking periods for running processes (directly attaching to process can freeze its work for a second or so, which isn&#8217;t that tolerable in production environments). GDB is getting closer to the async debugging capabilities &#8211; where one can run a debugger without actually stopping anything.</p>
<p>So, congratulations GDB team, now it is job for us to find all the uses of the tool. It has been invaluable so far, but this is much much more.</p>
]]></content:encoded>
			<wfw:commentRss>http://mituzas.lt/2009/10/08/gdb-7/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Evil replication management</title>
		<link>http://mituzas.lt/2009/07/30/evil-replication-management/</link>
		<comments>http://mituzas.lt/2009/07/30/evil-replication-management/#comments</comments>
		<pubDate>Thu, 30 Jul 2009 12:46:02 +0000</pubDate>
		<dc:creator>Domas Mituzas</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[evil]]></category>
		<category><![CDATA[gdb]]></category>
		<category><![CDATA[replication]]></category>

		<guid isPermaLink="false">http://mituzas.lt/?p=567</guid>
		<description><![CDATA[When one wants to script automated replication chain building, certain things are quite annoying, like immutable replication configuration variables. For example, at certain moments log_slave_updates is more than needed, and thats what the server says: mysql> show variables like 'log_slave_updates'; &#8230; <a href="http://mituzas.lt/2009/07/30/evil-replication-management/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When one wants to script automated replication chain building, certain things are quite annoying, like immutable replication configuration variables. For example, at certain moments log_slave_updates is more than needed, and thats what the server says:</p>
<pre>
mysql> show variables like 'log_slave_updates';
+-------------------+-------+
| Variable_name     | Value |
+-------------------+-------+
| log_slave_updates | OFF   |
+-------------------+-------+
1 row in set (0.00 sec)

mysql> set global log_slave_updates=1;
ERROR 1238 (HY000): Variable 'log_slave_updates' is a read only variable
</pre>
<p>Of course, there are few options, roll in-house fork (heheeeee!), restart your server, and keep warming up your tens of gigabytes of cache arenas, or wait for MySQL to ship a feature change in next major release. Then there are evil tactics:</p>
<pre>
mysql> system gdb -p $(pidof mysqld)
                       -ex "set opt_log_slave_updates=1" -batch
mysql> show variables like 'log_slave_updates';
+-------------------+-------+
| Variable_name     | Value |
+-------------------+-------+
| log_slave_updates | ON    |
+-------------------+-------+
1 row in set (0.00 sec)
</pre>
<p>I don&#8217;t guarantee safety of this when slave is running, but&#8230; stopping and starting slave threads is somewhat cheaper, than stopping and starting big database instance, right?</p>
<p>What else can we do? </p>
<pre>
mysql> show slave status \G
...
     Replicate_Do_DB: test
...
mysql> system gdb -p $(pidof mysqld)
          -ex 'call rpl_filter->add_do_db(strdup("hehehe"))' -batch
mysql> show slave status \G
...
      Replicate_Do_DB: test,hehehe
...
</pre>
<p>It is actually possible to add all sorts of filters this way, rpl_filter.h can be good reference :) So now that you want to throw out some data from your slaves, restart isn&#8217;t needed. Unfortunately, deleting entries isn&#8217;t possible via rpl_filter methods, but you can always edit base_ilists, can&#8217;t you?</p>
<p>P.S. having this functionality inside server would definitely be best. </p>
]]></content:encoded>
			<wfw:commentRss>http://mituzas.lt/2009/07/30/evil-replication-management/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>On binaries and -fomit-frame-pointer</title>
		<link>http://mituzas.lt/2009/07/26/on-binaries-and-fomit-frame-pointer/</link>
		<comments>http://mituzas.lt/2009/07/26/on-binaries-and-fomit-frame-pointer/#comments</comments>
		<pubDate>Sun, 26 Jul 2009 21:16:17 +0000</pubDate>
		<dc:creator>Domas Mituzas</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[compiling]]></category>
		<category><![CDATA[gdb]]></category>
		<category><![CDATA[oprofile]]></category>
		<category><![CDATA[x86_64]]></category>

		<guid isPermaLink="false">http://mituzas.lt/?p=545</guid>
		<description><![CDATA[Over last few years 64-bit x86 platform has became ubiquitous, thus making stupid memory limitations a thing of some forgotten past. 64-bit processors made internal memory structures bigger, but compensated that with twice the amount and twice larger registers. But &#8230; <a href="http://mituzas.lt/2009/07/26/on-binaries-and-fomit-frame-pointer/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Over last few years 64-bit x86 platform has became ubiquitous, thus making stupid memory limitations a thing of some forgotten past. 64-bit processors made internal memory structures bigger, but compensated that with twice the amount and twice larger registers. </p>
<p>But there&#8217;s one thing that definitely got worse &#8211; gcc, the compiler, has a change in default compilation options &#8211; it omits frame pointers from binaries in x86_64 architecture. People have advocated against that <a href='http://lkml.indiana.edu/hypermail/linux/kernel/9702.3/0214.html'>back in 1997</a> because of very simple reasons, that are still very much existing today too &#8211; frame pointers are needed for efficient stack trace calculations, and stack traces are very very useful, sometimes. </p>
<p>So, this change means that oprofile is not able to give hierarchical profiles, it also means that MySQL crash information will not include most useful bit &#8211; the failing stack trace. This decision has been just because of performance reasons &#8211; frame pointer takes whole register (though on x86_32 that meant 1 out of 8, on x86_64 it is 1 out of 16), which could be used to optimize the application. </p>
<p>I tested two MySQL builds, one built with &#8216;-O3 -g -fno-omit-frame-pointer&#8217; and other with -fomit-frame-pointer instead &#8211; and performance difference was negligible. It was around <b>1%</b> in sysbench tests, and slightly over <b>3%</b> at tight-loop <code>select benchmark(100000000,(select asin(5+5)+sin(5+5)));</code> on a 2-cpu Opteron box.</p>
<p>The summary suggestion for this flag would be very simple. If you don&#8217;t care about fixing or making your product faster, you can probably use 1% speed-up. But if getting actual real-time performance data can lead to much better performance fixes, and fast introspection means qualified engineers can diagnose problems much faster, 1% or even 3% is not that much. So, add &#8216;-fno-omit-frame-pointer&#8217; to CFLAGS and CXXFLAGS, and enjoy things getting back to normal :) </p>
<p>By the way, while I was at it, I did some empiric tests of other options, but one that irks me most is not using &#8216;-g&#8217; on production binaries. See, debugging information, symbol tables, etc &#8211; they all cause around 0% performance difference. The only difference is that e.g. mysqld binary will weight 30M, instead of 6M (though that fat will not be loaded into RAM, and will only cost diskspace). </p>
<p>Why does debugging information matter? It doesn&#8217;t, if you don&#8217;t attempt to be power-user. It does, if you enjoy crazy debugger tricks (like one <a href='http://mituzas.lt/2009/05/28/checksums-again-some-io-too/'>here</a> or <a href='http://mituzas.lt/2009/03/14/stupid-innodb-tricks/'>here</a>). Oh, and of course, bonus GDB trick, how to run KILL without connecting to server:</p>
<pre>
(gdb) thread apply all bt
...
(gdb) thread 2
[Switching to thread 2 (Thread 0x44a76950 (LWP 23955))]#0  ...
(gdb) bt
#0  0x00007f7821e68e1d in pthread_cond_timedwait...
#1  0x000000000052dc0e in Item_func_sleep::val_int (this=0x12317f0)...
#2  0x0000000000501484 in Item::send (this=0x12317f0, ...
...
#15 0x00000000005caf29 in do_command (thd=0x11da290) ...
...
(gdb) frame 15
#15 0x00000000005caf29 in do_command (thd=0x11da290) at sql_parse.cc:854
854	  return_value= dispatch_command(command, thd, packet+1, ...
(gdb) set thd->killed = THD::KILL_QUERY
(gdb) continue
</pre>
<p>And the client gets <i>&#8216;ERROR 1317 (70100): Query execution was interrupted&#8217;</i> :-)</p>
]]></content:encoded>
			<wfw:commentRss>http://mituzas.lt/2009/07/26/on-binaries-and-fomit-frame-pointer/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Checksums again, some I/O too</title>
		<link>http://mituzas.lt/2009/05/28/checksums-again-some-io-too/</link>
		<comments>http://mituzas.lt/2009/05/28/checksums-again-some-io-too/#comments</comments>
		<pubDate>Thu, 28 May 2009 07:53:11 +0000</pubDate>
		<dc:creator>Domas Mituzas</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[checksums]]></category>
		<category><![CDATA[gdb]]></category>
		<category><![CDATA[innodb]]></category>

		<guid isPermaLink="false">http://dammit.lt/?p=502</guid>
		<description><![CDATA[When I was doing data loading tests, I realized that usually low checksum calculation CPU percentage is actually the blocking factor. See, usually when background writers do the flushing, it gets parallelized, but if active query is forcing a checkpoint, &#8230; <a href="http://mituzas.lt/2009/05/28/checksums-again-some-io-too/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When I was doing data loading tests, I realized that usually low checksum calculation CPU percentage is actually the blocking factor. See, usually when background writers do the flushing, it gets parallelized, but if active query is forcing a checkpoint, it all happens in &#8216;foreground&#8217; thread, checksum computation included. This is where more Sun-ish wisdom (these people tune kernel with debugger all the time) comes in:</p>
<pre>gdb -p $(pidof mysqld) -ex "set srv_use_checksums=0" --batch</pre>
<p>Puff. Everything becomes much faster. Of course, one would be able to restart the server with &#8211;skip-innodb-checksums, but that would interrupt the whole process, etc. Of course, proper people would implement tunable parameter (5 lines of code, or so), but anyone with Solaris experience knows how to <a href='http://docs.sun.com/app/docs/doc/817-1759/6mhfh76f2?a=view'>tune stuff with debuggers</a>, hahaha. </p>
<p>Odd though, I <a href='http://dammit.lt/2008/05/29/on-checksums/'>was used</a> to compiled -O3 mode optimizing checksums to disappear from profiles, so either this doesn&#8217;t work, or it just got so much emphasis to actually matter. This is why I told Heikki at the Users Conference, that checksums &#8216;must go&#8217; or be fixed in one way or another. Even when they&#8217;re small part of operation and doesn&#8217;t cost anything if it doesn&#8217;t block primary operations (e.g. happens in parallel), people keep accessing SSDs, and then relative cost of checksum is insane. </p>
<p>It is quite easy to check that, just run InnoDB with tiny buffer pool, OS caching, and try some benchmarking with checksums enabled and disabled &#8211; there will be a huge difference, which may simply explain the performance difference of caching at buffer pool and OS buffers. Turn checksums off, and OS caching may be even tolerable for your workloads. </p>
<p>Other interesting issue here is that MarkC has lots of I/O path optimization in his fourth (and four is a good number!) patch. Now&#8230; maybe everyone will be soon caching pages in OS, once some more work is done in I/O access path cost work? </p>
]]></content:encoded>
			<wfw:commentRss>http://mituzas.lt/2009/05/28/checksums-again-some-io-too/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Poor man&#8217;s contention profiling</title>
		<link>http://mituzas.lt/2009/02/15/poor-mans-contention-profiling/</link>
		<comments>http://mituzas.lt/2009/02/15/poor-mans-contention-profiling/#comments</comments>
		<pubDate>Sun, 15 Feb 2009 12:55:50 +0000</pubDate>
		<dc:creator>Domas Mituzas</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[contention]]></category>
		<category><![CDATA[gdb]]></category>
		<category><![CDATA[profiling]]></category>

		<guid isPermaLink="false">http://dammit.lt/?p=378</guid>
		<description><![CDATA[I wrote already about poor man&#8217;s query profiling techniques last summer. Today I&#8217;m going to share poor man&#8217;s contention profiling tool, for all these poor souls which do not have Solaris with dtrace or pstack, don&#8217;t want to run tcmalloc &#8230; <a href="http://mituzas.lt/2009/02/15/poor-mans-contention-profiling/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I wrote already about <a href='http://dammit.lt/2008/05/22/poor-mans-query-profiling/'>poor man&#8217;s query profiling</a> techniques last summer. Today I&#8217;m going to share poor man&#8217;s contention profiling tool, for all these poor souls which do not have Solaris with dtrace or pstack, don&#8217;t want to run tcmalloc contention profiler, and simply need some easy hack to see &#8216;what the heck is going on in my server&#8217;. Here it is:</p>
<pre>
gdb \
    -ex "set pagination 0" \
    -ex "thread apply all bt" \
    --batch -p $(pidof mysqld)
</pre>
<p>Run few times, and you will have enough samples to start judging. Do note, this may stop the process execution for a second, so do not spam it in too tight loop.<br />
Once you have results it is just a matter of 20-liner script to extract any useful calculations :) </p>
<p>P.S. I&#8217;d love to see efficient pstack implementation for 64-bit Linux :) </p>
<p><b>update:</b> this now lives at <a href='http://poormansprofiler.org'>http://poormansprofiler.org</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mituzas.lt/2009/02/15/poor-mans-contention-profiling/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
