Stewart Smith wrote:
> On Wed, Aug 05, 2009 at 03:13:34PM +1000, Arjen Lentz wrote:
>> The issue in MySQL has been overhead of such instrumentation,  
>> particularly also when not used. Some cause 5-20% perf loss which is  
>> unacceptable.
> 
> 110% agree.
> 
> If you're not doing analysis of anything, it shouldn't cost you.
> 
> You also shouldn't have to restart, rebuild or anything like that.
> 
> I think I know how to do this too.
> 
> 
> I have this inkling that it's the "if(profiling_enabled)" inserted
> everywhere that kills us.
> 
> This is pretty easy to check. Say we have some function f() that is
> going to do some counting for us (e.g. number of rows fetched, number of
> times mutex X was taken). If profiling is disabled, we want this to use
> 0 CPU.
> 
> calling an empty function int f(int) a billion times in a loop is
> roughly equivilnet of just running through the loop (yes, i built with
> gcc -O0 and checked the produced code). By roughly I do mean next to
> impossible to measure.
> 
> If you add a simple "if(x) something;" to the function f(), it is
> noticably slower! (roughly 20% in my tests).
> 
> So we really don't want to do that compare.
> 
> Now... about this time somebody is going to jump up and suggest using
> DTrace to insert code at runtime. Not on Linux, so is worse than useless
> here.
> 
> But we can do some cool self modifying code tricks.
> 
> The same do-nothing f() does not take any longer to run if we insert a few
> no-ops. (i tried inserting 4 NOP instructions, which are single byte...
> i do wonder if the multi-byte NOP instruction could help here too).
> 
> So... when a profile hook is enabled, we just modify f() to call the
> real profiling function. This can either be done with an atomic
> instruction writing out the appropriate CALL instruction, or we can put
> in a small JMP around the NOPs as we fill it out.
> 
> 
> and there's a number of tricks to do this pretty easily for all the
> possible points to hook in profiling stuff.
> 

I like this - which is odd, because I don't normally like things like
this. But in this case..

++

Monty

_______________________________________________
Mailing list: https://launchpad.net/~drizzle-discuss
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~drizzle-discuss
More help   : https://help.launchpad.net/ListHelp

Reply via email to