<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Apr 7, 2011, at 9:19 AM, Andrew Bennetts wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Itamar Turner-Trauring wrote:<br>[…]<br><blockquote type="cite">So, the design has to *not* rely on caching working.<br></blockquote><br>FWIW: this is an achievable goal. &nbsp;I have 32 different bzr plugins<br>currently installed, and here's the difference they make:<br><br> &nbsp;&nbsp;$ time bzr --no-plugins rocks<br> &nbsp;&nbsp;It sure does!<br><br> &nbsp;&nbsp;real<span class="Apple-tab-span" style="white-space:pre">        </span>0m0.075s<br><br> &nbsp;&nbsp;$ time bzr rocks<br> &nbsp;&nbsp;It sure does!<br><br> &nbsp;&nbsp;real<span class="Apple-tab-span" style="white-space:pre">        </span>0m0.119s<br><br>So that's about 1.5ms per plugin, on average. &nbsp;With a hot disk cache, at<br>least…<br></div></blockquote><div><br></div><div>Is your cache as hot for Twisted as for bzr? &nbsp;Have you replicated these results in a randomized, double-blind clinical trial? ;-)</div><div><br></div><div>I'm not surprised that bzr has faster startup though; twistd has not been (and doubtful will ever be) nearly so ruthlessly optimized. &nbsp;Maybe it's time to put a startup benchmark on &lt;<a href="http://speed.twistedmatrix.com/">http://speed.twistedmatrix.com/</a>&gt;, at least that way we could keep track.</div><br><blockquote type="cite"><div>For comparison, 'twistd --version' takes 116ms, with a dropin.cache and<br>(I think, although how can I tell?) no plugins installed.<br></div></blockquote><div><br></div><div>Twisted itself installs 22 dropins (python files which each define at least one plugin), which comprise 48 plugins of various types, so there are always some. &nbsp;You <i>should</i> be able to tell, though. &nbsp;It's pathetic that we don't have a command-line tool to inspect the available plugins and what they're doing. &nbsp;Independent of the other issues under discussion here: &lt;<a href="http://twistedmatrix.com/trac/ticket/5039">http://twistedmatrix.com/trac/ticket/5039</a>&gt;.</div><div><br></div><div>But this is all moot. &nbsp;'twistd --version' doesn't scan for plugins, so that's all just the normal startup time; apparently we import too much in the first place. &nbsp;The thing to compare with is 'twistd --help' or even just 'twistd [some-plugin]' (since invoking one plugin actually loads all of them). &nbsp;Plus - this is really the genesis for this thread - the dropin.cache isn't really saving us much work at all right now, because all the plugins get loaded anyway for all practical uses of plugin scanning.</div><div><br></div><blockquote type="cite"><div>In part, we achieve this via the bzrlib.lazy_import hack, which plugins<br>can and often do use, and by encouraging plugin authors to put as little<br>code into their __init__.py files as possible. &nbsp;A typical plugin's<br>__init__ might do just:<br><br> &nbsp;&nbsp;&nbsp;# This is example_plugin/__init__.py<br> &nbsp;&nbsp;&nbsp;# The actual command implementation is in<br> &nbsp;&nbsp;&nbsp;# example_plugin/example_commands.py<br> &nbsp;&nbsp;&nbsp;from bzrlib import commands<br> &nbsp;&nbsp;&nbsp;commands.plugin_cmds.register_lazy('cmd_class_name', [],<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'bzrlib.plugins.example_plugin.example_commands')<br></div></blockquote><div><br></div><div>This looks very similar to ServiceMaker.</div><div><br></div><blockquote type="cite"><div>Glyph's expressed scepticism that plugin authors and maintainers will<br>know to keep their __init__.py files cheap to import. &nbsp;Bazaar's<br>experience is different. &nbsp;Partly that's probably because the Bazaar<br>community has paid a fair bit of attention to start up time and I<br>suppose Twisted doesn't have that.</div></blockquote><div><br></div><div>Yeah,&nbsp;bzr's audience makes this easier. &nbsp;For one thing, the audience is much bigger :), but more importantly, bzr is a user-facing tool which users are running _constantly_ at the command line. &nbsp;The only visible consequence of a rogue twistd plugin is that your server which runs for days at a time takes 0.2s longer to start; the real problem sets in later, where your 25 subprocesses are suddenly consuming an additional 50meg each because of the extra plugin they loaded. &nbsp;You do find this eventually, it's just rare to find it while you're writing the plugin.</div><br><blockquote type="cite"><div>But I think also it's partly because<br>we've provided tools to help people diagnose what/who to blame for bzr<br>being slow to start, like 'bzr --profile-imports', and even the crude<br>'time bzr rocks'.<br></div></blockquote></div><div><br></div>Yes. &nbsp;These are a great idea, and there's no excuse that Twisted's plugin system is so difficult to inspect and debug. &nbsp;A couple of good tools would address a wide range of plugin issues, many of them much more interesting than performance, like the ever-popular "why isn't my plugin getting loaded". &nbsp;Thanks for the impetus to file the ticket above. &nbsp;(I kinda hope it's a dup, but I couldn't find one.)</body></html>