dhcp-perf-guide.xml 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [
  4. <!ENTITY mdash "&#x2014;" >
  5. <!ENTITY % version SYSTEM "version.ent">
  6. %version;
  7. ]>
  8. <!--
  9. - Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
  10. -
  11. - Permission to use, copy, modify, and/or distribute this software for any
  12. - purpose with or without fee is hereby granted, provided that the above
  13. - copyright notice and this permission notice appear in all copies.
  14. -
  15. - THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  16. - REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  17. - AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  18. - INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  19. - LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  20. - OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  21. - PERFORMANCE OF THIS SOFTWARE.
  22. -->
  23. <book>
  24. <?xml-stylesheet href="bind10-guide.css" type="text/css"?>
  25. <bookinfo>
  26. <title>DHCP Performance Guide</title>
  27. <!-- <subtitle>Various aspects of DHCP Performance in BIND 10</subtitle> -->
  28. <copyright>
  29. <year>2012</year>
  30. <holder>Internet Systems Consortium, Inc. ("ISC")</holder>
  31. </copyright>
  32. <author>
  33. <firstname>Tomasz</firstname>
  34. <surname>Mrugalski</surname>
  35. </author>
  36. <abstract>
  37. <para>BIND 10 is a framework that features Domain Name System
  38. (DNS) and Dynamic Host Configuration Protocol (DHCP)
  39. software with development managed by Internet Systems Consortium (ISC).
  40. This document describes various aspects of DHCP performance,
  41. measurements and tuning. It covers BIND 10 DHCP (codename Kea),
  42. existing ISC DHCP4 software, perfdhcp (a DHCP performance
  43. measurement tool) and other related topics.</para>
  44. </abstract>
  45. <releaseinfo>This is a companion document for BIND 10 version
  46. &__VERSION__;.</releaseinfo>
  47. </bookinfo>
  48. <preface>
  49. <title>Preface</title>
  50. <section id="acknowledgements">
  51. <title>Acknowledgements</title>
  52. <para>ISC would like to acknowledge generous support for
  53. BIND 10 development of DHCPv4 and DHCPv6 components provided
  54. by <ulink url="http://www.comcast.com/">Comcast</ulink>.</para>
  55. </section>
  56. </preface>
  57. <chapter id="intro">
  58. <title>Introduction</title>
  59. <para>
  60. This document is in the early stages of development. It is
  61. expected to grow significantly in the near future. It will
  62. cover topics like database backend perfomance measurements,
  63. tools, and the pros an cons of various optimization techniques.
  64. </para>
  65. </chapter>
  66. <chapter id="dhcp4">
  67. <title>ISC DHCP 4.x</title>
  68. <para>
  69. TODO: Write something about ISC DHCP4 here.
  70. </para>
  71. </chapter>
  72. <chapter id="kea">
  73. <title>Kea</title>
  74. <para>
  75. </para>
  76. <section>
  77. <title>Backend performance evaluation</title>
  78. <para>
  79. Kea will support several different database backends, using
  80. both popular databases (like MySQL or SQLite) and
  81. custom-developed solutions (such as an in-memory database).
  82. To aid in the choice of backend, the BIND 10
  83. source code features a set of performance microbenchmarks.
  84. Written in C/C++, these are small tools that simulate expected
  85. DHCP server behaviour and evaluate the performance of
  86. considered databases. As implemented, the benchmarks are not really
  87. simulating DHCP operation, but rather use set of primitives
  88. that can be used by a real server. For this reason, they are called
  89. micro-benchmarks.
  90. </para>
  91. <para>Although there are many operations and data types that
  92. server could store in a database, the most frequently used data
  93. type is lease information. Although the information held for IPv4
  94. and IPv6 leases differs slightly, it is expected that the performance
  95. differences will be minimal between IPv4 and IPv6 lease operations.
  96. Therefore each test uses the lease4 table (in which IPv4 leases are stored)
  97. for performance measurements.
  98. </para>
  99. <para>All benchmarks are implemented as single threaded applications
  100. that take advantage of a single database connection.</para>
  101. <para>
  102. Those benchmarks are stored in tests/tools/dhcp-ubench
  103. directory of the BIND 10 source tree. This directory contains simplified prototypes for
  104. the various database back-ends that are planned or considered as a
  105. possibly for BIND10 DHCP. Athough trivial now, the benchmarks are
  106. expected to evolve into useful tools that will allow users to
  107. measure performance in their specific environment.
  108. </para>
  109. <para>
  110. Currently the following benchmarks are implemented:
  111. <itemizedlist>
  112. <listitem><para>In memory + flat file</para></listitem>
  113. <listitem><para>SQLite</para></listitem>
  114. <listitem><para>MySQL</para></listitem>
  115. </itemizedlist>
  116. </para>
  117. <para>
  118. As the benchmarks require additional (sometimes heavy) dependencies, they are not
  119. built by default. Actually, their build system is completely separate from that
  120. of the rest of BIND 10.
  121. It is anticipated that they will be eventually merged into the rest of BIND 10, but
  122. that is a low priority for now.
  123. </para>
  124. <para>
  125. All benchmarks will follow the same pattern:
  126. <orderedlist>
  127. <listitem><para>Prepare operation (connect to a database, create a file etc.)</para></listitem>
  128. <listitem><para>Measure timestamp 0</para></listitem>
  129. <listitem><para>Commit new lease4 record (repeated N times)</para></listitem>
  130. <listitem><para>Measure timestamp 1</para></listitem>
  131. <listitem><para>Search for random lease4 record (repeated N times)</para></listitem>
  132. <listitem><para>Measure timestamp 2</para></listitem>
  133. <listitem><para>Update existing lease4 record (repeated N times)</para></listitem>
  134. <listitem><para>Measure timestamp 3</para></listitem>
  135. <listitem><para>Delete existing lease4 record (repeated N times)</para></listitem>
  136. <listitem><para>Measure timestamp 4</para></listitem>
  137. <listitem><para>Print out statistics, based on N and measured timestamps.</para></listitem>
  138. </orderedlist>
  139. Although this approach does not attempt to simulate actual DHCP server
  140. operation that has mix of all steps, it answers the
  141. questions about basic database strengths and weak points. In particular
  142. it can show what is the impact of specific database optimizations, such as
  143. changing engine, optimizing for writes/reads etc.
  144. </para>
  145. <para>
  146. The framework attempts to do the same amount of work for every
  147. backend thus allowing fair complarison between them.
  148. </para>
  149. </section>
  150. <section id="mysql-backend">
  151. <title>MySQL backend</title>
  152. <para>The MySQL backend requires the MySQL client development libraries. It uses
  153. the mysql_config tool (similar to pkg-config) to discover required
  154. compilation and linking options. To install required packages on Ubuntu,
  155. use the following command:
  156. <screen>$ <userinput>sudo apt-get install mysql-client mysql-server libmysqlclient-dev</userinput></screen>
  157. Make sure that MySQL server is running. Make sure that you have your setup
  158. configured so there is a user that is able to modify used database.</para>
  159. <para>Before running tests, you need to initialize your database. You can
  160. use mysql.schema script for that purpose.</para>
  161. <para><emphasis>WARNING: It will drop existing
  162. Kea database. Do not run this on your production server. </emphasis></para>
  163. <para>Assuming your
  164. MySQL user is "kea", you can initialize your test database by:
  165. <screen>$ <userinput>mysql -u kea -p &lt; mysql.schema</userinput></screen>
  166. </para>
  167. <para>After the database is initialized, you are ready to run the test:
  168. <screen>$ <userinput>./mysql_ubench</userinput></screen>
  169. or
  170. <screen>$ <userinput>./mysql_ubench &gt; results-mysql.txt</userinput></screen>
  171. Redirecting output to a file is important, because for each operation
  172. there is a single character printed to show progress. If you have a slow
  173. terminal, this may considerably affect test performance. On the other hand,
  174. printing something after each operation is required as poor database settings
  175. may slow down operations to around 20 per second. (The observant user is expected
  176. to note that the initial dots are printed too slowly and abort the test.)</para>
  177. <para>Currently all default parameters are hardcoded. Default values can be
  178. overridden using command line switches. Although all benchmarks take
  179. the same list of parameters, some of them are specific to a given backend.
  180. To get a list of supported parameters, run the benchmark with the "-h" option:
  181. <screen>$ <userinput>./mysql_ubench -h</userinput>
  182. This is a benchmark designed to measure expected performance
  183. of several backends. This particular version identifies itself
  184. as following:
  185. MySQL client version is 5.5.24
  186. Possible command-line parameters:
  187. -h - help (you are reading this)
  188. -m hostname - specifies MySQL server to connect (MySQL backend only)
  189. -u username - specifies MySQL user name (MySQL backend only)
  190. -p password - specifies MySQL passwod (MySQL backend only)
  191. -f name - database or filename (MySQL, SQLite and memfile)
  192. -n integer - number of test repetitions (MySQL, SQLite and memfile)
  193. -s yes|no - synchronous/asynchronous operation (MySQL, SQLite and memfile)
  194. -v yes|no - verbose mode (MySQL, SQLite and memfile)
  195. -c yes|no - should compiled statements be used (MySQL only)
  196. </screen>
  197. </para>
  198. <para>Synchronous operation requires database backend to
  199. physically store changes to disk before proceeding. This
  200. property ensures that no data is lost in case of the server
  201. failure. Unfortunately, it slows operation
  202. considerably. Asynchronous mode allows database to write data at
  203. a later time (usually controlled by the database engine on OS
  204. disk buffering mechanism).</para>
  205. <section>
  206. <title>MySQL tweaks</title>
  207. <para>One parameter that has huge impact on performance is the choice of backend engine.
  208. You can get a list of engines of your MySQL implementation by using
  209. <screen>&gt; <userinput>show engines;</userinput></screen>
  210. in your mysql client. Two notable engines are MyISAM and InnoDB. mysql_ubench uses
  211. use MyISAM for synchronous mode and InnoDB for asynchronous. Please use
  212. '-s yes|no' to choose whether you want synchronous or asynchronous operations.</para>
  213. <para>Another parameter that affects performance are precompiled statements.
  214. In a basic approach, the actual SQL query is passed as a text string that is
  215. then parsed by the database engine. Alternative is a so called precompiled
  216. statement. In this approach the SQL query is compiled an specific values are being
  217. bound to it. In the next iteration the query remains the same, only bound values
  218. are changing (e.g. searching for a different address). Usage of basic or precompiled
  219. statements is controlled with '-c no|yes'.</para>
  220. </section>
  221. </section>
  222. <section id="sqlite-ubench">
  223. <title>SQLite-ubench</title>
  224. <para>The SQLite backend requires both the sqlite3 development and run-time packages. Their
  225. names may vary from system to system, but on Ubuntu 12.04 they are called
  226. sqlite3 libsqlite3-dev. To install them, use the following command:
  227. <screen>&gt; <userinput>sudo apt-get install sqlite3 libsqlite3-dev</userinput></screen>
  228. Before running the test the database has to be created. Use the following command for that:
  229. <screen>&gt; <userinput>cat sqlite.schema | sqlite3 sqlite.db</userinput></screen>
  230. A new database called sqlite.db will be created. That is the default name used
  231. by sqlite_ubench test. If you prefer other name, make sure you update
  232. sqlite_ubench.cc accordingly.</para>
  233. <para>Once the database is created, you can run tests:
  234. <screen>&gt; <userinput>./sqlite_ubench</userinput></screen>
  235. or
  236. <screen>&gt; <userinput>./sqlite_ubench > results-sqlite.txt</userinput></screen>
  237. </para>
  238. <section id="sqlite-tweaks">
  239. <title>SQLite tweaks</title>
  240. <para>To modify default sqlite_ubench parameters, command line
  241. switches can be used. The currently supported switches are
  242. (default values specified in brackets):
  243. <orderedlist>
  244. <listitem><para>-f filename - name of the database file ("sqlite.db")</para></listitem>
  245. <listitem><para>-n num - number of iterations (100)</para></listitem>
  246. <listitem><para>-s yes|no - should the operations be performed in a synchronous (yes)
  247. or asynchronous (no) manner (yes)</para></listitem>
  248. <listitem><para>-v yes|no - verbose mode. Should the test print out progress? (yes)</para></listitem>
  249. <listitem><para>-c yes|no - precompiled statements. Should the SQL statements be precompiled?</para></listitem>
  250. </orderedlist>
  251. </para>
  252. <para>SQLite can run in asynchronous or synchronous mode. This
  253. mode can be controlled by using "synchronous" parameter. It is set
  254. using the SQLite command:</para>
  255. <para><command>PRAGMA synchronous = ON|OFF</command></para>
  256. <para>Another tweakable feature is journal mode. It can be
  257. turned to several modes of operation. Its value can be
  258. modified in SQLite_uBenchmark::connect(). See
  259. http://www.sqlite.org/pragma.html#pragma_journal_mode for
  260. detailed explanantion.</para>
  261. <para>sqlite_bench supports precompiled statements. Please use
  262. '-c no|yes' to define which should be used: basic SQL query (no) or
  263. precompiled statement (yes).</para>
  264. </section>
  265. </section>
  266. <section id="memfile-ubench">
  267. <title>memfile-ubench</title> <para>The memfile backend is a
  268. custom backend that somewhat mimics operation of ISC DHCP4. It
  269. implements in-memory storage using standard C++ and boost
  270. mechanisms (std::map and boost::shared_ptr&lt;&gt;). All
  271. database changes are also written to a lease file, which is
  272. strictly write-only. This approach takes advantage of the fact
  273. that file append operation is faster than modifications introduced
  274. in the middle of the file (as it often requires moving all data
  275. after modified point, effectively requiring writing large parts of
  276. the whole file, not just changed fragment).</para>
  277. <section id="memfile-tweaks">
  278. <title>memfile tweaks</title>
  279. <para>To modify default memfile_ubench parameters, command line
  280. switches can be used. Currently supported switches are
  281. (default values specified in brackets):
  282. <orderedlist>
  283. <listitem><para>-f filename - name of the database file ("dhcpd.leases")</para></listitem>
  284. <listitem><para>-n num - number of iterations (100)</para></listitem>
  285. <listitem><para>-s yes|no - should the operations be performend in a synchronous (yes)
  286. or asynchronous (no) manner (yes)</para></listitem>
  287. <listitem><para>-v yes|no - verbose mode. Should the test print out progress? (yes)</para></listitem>
  288. </orderedlist>
  289. </para>
  290. <para>memfile can run in asynchronous or synchronous mode. This
  291. mode can be controlled by using sync parameter. It uses
  292. fflush() and fsync() in synchronous mode to make sure that
  293. data is not buffered and physically stored on disk.</para>
  294. </section>
  295. </section>
  296. <section>
  297. <title>Basic performance measurements</title>
  298. <para>This section contains sample results for backend performance measurements,
  299. taken using microbenchmarks. Tests were conducted on reasonably powerful machine:
  300. <screen>
  301. CPU: Quad-core Intel(R) Core(TM) i7-2600K CPU @ 3.40GHz (8 logical cores)
  302. HDD: 1,5TB Seagate Barracuda ST31500341AS 7200rpm, ext4 partition
  303. OS: Ubuntu 12.04, running kernel 3.2.0-26-generic SMP x86_64
  304. compiler: g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
  305. MySQL version: 5.5.24
  306. SQLite version: 3.7.9sourceid version is 2011-11-01 00:52:41 c7c6050ef060877ebe77b41d959e9df13f8c9b5e</screen>
  307. </para>
  308. <para>The benchmarks were run without using precompiled statements.
  309. The code was compiled with the -O0 flag (no code optimizations).
  310. Each run was executed once.</para>
  311. <para>Two series of measures were made, synchronous and
  312. asynchronous. As those modes offer radically different
  313. performances, synchronous mode was conducted for one
  314. thousand repetitions and asynchronous mode was conducted for
  315. one hundred thousand repetitions.</para>
  316. <!-- raw results sync -->
  317. <table><title>Synchronous results (basic)</title>
  318. <tgroup cols='6' align='center' colsep='1' rowsep='1'>
  319. <colspec colname='Backend'/>
  320. <colspec colname='Num' />
  321. <colspec colname='Create'/>
  322. <colspec colname='Search'/>
  323. <colspec colname='Update'/>
  324. <colspec colname='Delete'/>
  325. <colspec colname='Average'/>
  326. <thead>
  327. <row>
  328. <entry>Backend</entry>
  329. <entry>Operations</entry>
  330. <entry>Create [s]</entry>
  331. <entry>Search [s]</entry>
  332. <entry>Update [s]</entry>
  333. <entry>Delete [s]</entry>
  334. <entry>Average [s]</entry>
  335. </row>
  336. </thead>
  337. <tbody>
  338. <row>
  339. <entry>MySQL</entry>
  340. <entry>1,000</entry>
  341. <entry>31.604</entry>
  342. <entry> 0.117</entry>
  343. <entry>27.964</entry>
  344. <entry>27.695</entry>
  345. <entry>21.845</entry>
  346. </row>
  347. <row>
  348. <entry>SQLite</entry>
  349. <entry>1,000</entry>
  350. <entry>61.421</entry>
  351. <entry> 0.033</entry>
  352. <entry>59.477</entry>
  353. <entry>56.034</entry>
  354. <entry>44.241</entry>
  355. </row>
  356. <row>
  357. <entry>memfile</entry>
  358. <entry>1,000</entry>
  359. <entry>38.224</entry>
  360. <entry> 0.001</entry>
  361. <entry>38.041</entry>
  362. <entry>38.017</entry>
  363. <entry>28.571</entry>
  364. </row>
  365. </tbody>
  366. </tgroup>
  367. </table>
  368. <para>The following parameters were measured for asynchronous mode.
  369. MySQL and SQLite were run with one hundred thousand repetitions. Memfile
  370. was run for one million repetitions due to its much higher performance.</para>
  371. <!-- raw results async -->
  372. <table><title>Asynchronous results (basic)</title>
  373. <tgroup cols='6' align='center' colsep='1' rowsep='1'>
  374. <colspec colname='Backend'/>
  375. <colspec colname='Num' />
  376. <colspec colname='Create'/>
  377. <colspec colname='Search'/>
  378. <colspec colname='Update'/>
  379. <colspec colname='Delete'/>
  380. <colspec colname='Average'/>
  381. <thead>
  382. <row>
  383. <entry>Backend</entry>
  384. <entry>Operations</entry>
  385. <entry>Create [s]</entry>
  386. <entry>Search [s]</entry>
  387. <entry>Update [s]</entry>
  388. <entry>Delete [s]</entry>
  389. <entry>Average [s]</entry>
  390. </row>
  391. </thead>
  392. <tbody>
  393. <row>
  394. <entry>MySQL</entry>
  395. <entry>100,000</entry>
  396. <entry>10.585</entry>
  397. <entry>10.386</entry>
  398. <entry>10.062</entry>
  399. <entry> 8.890</entry>
  400. <entry> 9.981</entry>
  401. </row>
  402. <row>
  403. <entry>SQLite</entry>
  404. <entry>100,000</entry>
  405. <entry> 3.710</entry>
  406. <entry> 3.159</entry>
  407. <entry> 2.865</entry>
  408. <entry> 2.439</entry>
  409. <entry> 3.044</entry>
  410. </row>
  411. <row>
  412. <entry>memfile</entry>
  413. <entry>1,000,000</entry>
  414. <entry> 1.300</entry>
  415. <entry> 0.039</entry>
  416. <entry> 1.307</entry>
  417. <entry> 1.278</entry>
  418. <entry> 0.981</entry>
  419. </row>
  420. </tbody>
  421. </tgroup>
  422. </table>
  423. <para>The presented performance results can be converted into operations per second metrics.
  424. It should be noted that due to large differences between various operations (sometimes
  425. over three orders of magnitude), it is difficult to create a simple, readable chart with
  426. that data.</para>
  427. <table id="tbl-basic-perf-results"><title>Estimated basic performance</title>
  428. <tgroup cols='6' align='center' colsep='1' rowsep='1'>
  429. <colspec colname='Backend'/>
  430. <colspec colname='Create'/>
  431. <colspec colname='Search'/>
  432. <colspec colname='Update'/>
  433. <colspec colname='Delete'/>
  434. <colspec colname='Average'/>
  435. <thead>
  436. <row>
  437. <entry>Backend</entry>
  438. <entry>Create [oper/s]</entry>
  439. <entry>Search [oper/s]</entry>
  440. <entry>Update [oper/s]</entry>
  441. <entry>Delete [oper/s]</entry>
  442. <entry>Average [oper/s]</entry>
  443. </row>
  444. </thead>
  445. <tbody>
  446. <row>
  447. <entry>MySQL (async)</entry>
  448. <entry>9447.47</entry>
  449. <entry>9627.97</entry>
  450. <entry>9938.00</entry>
  451. <entry>11248.34</entry>
  452. <entry>10065.45</entry>
  453. </row>
  454. <row>
  455. <entry>SQLite (async)</entry>
  456. <entry>26951.59</entry>
  457. <entry>31654.29</entry>
  458. <entry>34899.70</entry>
  459. <entry>40993.59</entry>
  460. <entry>33624.79</entry>
  461. </row>
  462. <row>
  463. <entry>memfile (async)</entry>
  464. <entry>76944.27</entry>
  465. <entry>2542588.35</entry>
  466. <entry>76504.54</entry>
  467. <entry>78269.25</entry>
  468. <entry>693576.60</entry>
  469. </row>
  470. <row>
  471. <entry>MySQL (sync)</entry>
  472. <entry>31.64</entry>
  473. <entry>8575.45</entry>
  474. <entry>35.76</entry>
  475. <entry>36.11</entry>
  476. <entry>2169.74</entry>
  477. </row>
  478. <row>
  479. <entry>SQLite (sync)</entry>
  480. <entry>16.28</entry>
  481. <entry>20045.37</entry>
  482. <entry>16.81</entry>
  483. <entry>17.85</entry>
  484. <entry>7524.08</entry>
  485. </row>
  486. <row>
  487. <entry>memfile (sync)</entry>
  488. <entry>26.16</entry>
  489. <entry>1223990.21</entry>
  490. <entry>26.29</entry>
  491. <entry>26.30</entry>
  492. <entry>306017.24</entry>
  493. </row>
  494. </tbody>
  495. </tgroup>
  496. </table>
  497. <mediaobject>
  498. <imageobject>
  499. <imagedata fileref="performance-results-graph1.png" format="PNG"/>
  500. </imageobject>
  501. <textobject>
  502. <phrase>Basic performance measurements</phrase>
  503. </textobject>
  504. <caption>
  505. <para>Graphical representation of the basic performance results
  506. presented in table <xref linkend="tbl-basic-perf-results" />.</para>
  507. </caption>
  508. </mediaobject>
  509. </section>
  510. <section>
  511. <title>Optimized performance measurements</title>
  512. <para>This section contains sample results for backend performance measurements,
  513. taken using microbenchmarks. Tests were conducted on reasonably powerful machine:
  514. <screen>
  515. CPU: Quad-core Intel(R) Core(TM) i7-2600K CPU @ 3.40GHz (8 logical cores)
  516. HDD: 1,5TB Seagate Barracuda ST31500341AS 7200rpm, ext4 partition
  517. OS: Ubuntu 12.04, running kernel 3.2.0-26-generic SMP x86_64
  518. compiler: g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
  519. MySQL version: 5.5.24
  520. SQLite version: 3.7.9sourceid version is 2011-11-01 00:52:41 c7c6050ef060877ebe77b41d959e9df13f8c9b5e</screen>
  521. </para>
  522. <para>The benchmarks were run with precompiled statements enabled.
  523. The code was compiled with the -Ofast flag (optimize compilation for speed).
  524. Each run was repeated three times and measured values were averaged.</para>
  525. <para>Again the benchmarks were run in two series, synchronous and
  526. asynchronous. As those modes offer radically different
  527. performances, synchronous mode was conducted for one
  528. thousand repetitions and asynchronous mode was conducted for
  529. one hundred thousand repetitions.</para>
  530. <!-- raw results sync -->
  531. <table><title>Synchronous results (optimized)</title>
  532. <tgroup cols='6' align='center' colsep='1' rowsep='1'>
  533. <colspec colname='Backend'/>
  534. <colspec colname='Num' />
  535. <colspec colname='Create'/>
  536. <colspec colname='Search'/>
  537. <colspec colname='Update'/>
  538. <colspec colname='Delete'/>
  539. <colspec colname='Average'/>
  540. <thead>
  541. <row>
  542. <entry>Backend</entry>
  543. <entry>Operations</entry>
  544. <entry>Create [s]</entry>
  545. <entry>Search [s]</entry>
  546. <entry>Update [s]</entry>
  547. <entry>Delete [s]</entry>
  548. <entry>Average [s]</entry>
  549. </row>
  550. </thead>
  551. <tbody>
  552. <row>
  553. <entry>MySQL</entry>
  554. <entry>1,000</entry>
  555. <entry>27.887</entry>
  556. <entry> 0.106</entry>
  557. <entry>28.223</entry>
  558. <entry>27.696</entry>
  559. <entry>20.978</entry>
  560. </row>
  561. <row>
  562. <entry>SQLite</entry>
  563. <entry>1,000</entry>
  564. <entry>61.299</entry>
  565. <entry> 0.015</entry>
  566. <entry>59.648</entry>
  567. <entry>61.098</entry>
  568. <entry>45.626</entry>
  569. </row>
  570. <row>
  571. <entry>memfile</entry>
  572. <entry>1,000</entry>
  573. <entry>39.564</entry>
  574. <entry> 0.001</entry>
  575. <entry>39.543</entry>
  576. <entry>39.326</entry>
  577. <entry>29.608</entry>
  578. </row>
  579. </tbody>
  580. </tgroup>
  581. </table>
  582. <para>The following parameters were measured for asynchronous mode.
  583. MySQL and SQLite were run with one hundred thousand repetitions. Memfile
  584. was run for one million repetitions due to its much higher performance.</para>
  585. <!-- raw results async -->
  586. <table><title>Asynchronous results (optimized)</title>
  587. <tgroup cols='6' align='center' colsep='1' rowsep='1'>
  588. <colspec colname='Backend'/>
  589. <colspec colname='Num' />
  590. <colspec colname='Create'/>
  591. <colspec colname='Search'/>
  592. <colspec colname='Update'/>
  593. <colspec colname='Delete'/>
  594. <colspec colname='Average'/>
  595. <thead>
  596. <row>
  597. <entry>Backend</entry>
  598. <entry>Operations</entry>
  599. <entry>Create [s]</entry>
  600. <entry>Search [s]</entry>
  601. <entry>Update [s]</entry>
  602. <entry>Delete [s]</entry>
  603. <entry>Average [s]</entry>
  604. </row>
  605. </thead>
  606. <tbody>
  607. <row>
  608. <entry>MySQL</entry>
  609. <entry>100,000</entry>
  610. <entry>8.507</entry>
  611. <entry>9.698</entry>
  612. <entry>7.785</entry>
  613. <entry>8.326</entry>
  614. <entry>8.579</entry>
  615. </row>
  616. <row>
  617. <entry>SQLite</entry>
  618. <entry>100,000</entry>
  619. <entry> 1.562</entry>
  620. <entry> 0.949</entry>
  621. <entry> 1.513</entry>
  622. <entry> 1.502</entry>
  623. <entry> 1.382</entry>
  624. </row>
  625. <row>
  626. <entry>memfile</entry>
  627. <entry>1,000,000</entry>
  628. <entry>1.302</entry>
  629. <entry>0.038</entry>
  630. <entry>1.306</entry>
  631. <entry>1.263</entry>
  632. <entry>0.977</entry>
  633. </row>
  634. </tbody>
  635. </tgroup>
  636. </table>
  637. <para>The presented performance results can be converted into operations per second metrics.
  638. It should be noted that due to large differences between various operations (sometime
  639. over three orders of magnitude), it is difficult to create a simple, readable chart with
  640. the data.</para>
  641. <table id="tbl-optim-perf-results"><title>Estimated optimized performance</title>
  642. <tgroup cols='6' align='center' colsep='1' rowsep='1'>
  643. <colspec colname='Backend'/>
  644. <colspec colname='Create'/>
  645. <colspec colname='Search'/>
  646. <colspec colname='Update'/>
  647. <colspec colname='Delete'/>
  648. <colspec colname='Average'/>
  649. <thead>
  650. <row>
  651. <entry>Backend</entry>
  652. <entry>Create [oper/s]</entry>
  653. <entry>Search [oper/s]</entry>
  654. <entry>Update [oper/s]</entry>
  655. <entry>Delete [oper/s]</entry>
  656. <entry>Average [oper/s]</entry>
  657. </row>
  658. </thead>
  659. <tbody>
  660. <row>
  661. <entry>MySQL (async)</entry>
  662. <entry>11754.84</entry>
  663. <entry>10311.34</entry>
  664. <entry>12845.35</entry>
  665. <entry>12010.24</entry>
  666. <entry>11730.44</entry>
  667. </row>
  668. <row>
  669. <entry>SQLite (async)</entry>
  670. <entry>64005.90</entry>
  671. <entry>105391.29</entry>
  672. <entry>66075.51</entry>
  673. <entry>66566.43</entry>
  674. <entry>75509.78</entry>
  675. </row>
  676. <row>
  677. <entry>memfile (async)</entry>
  678. <entry>76832.16</entry>
  679. <entry>2636018.56</entry>
  680. <entry>76542.50</entry>
  681. <entry>79188.81</entry>
  682. <entry>717145.51</entry>
  683. </row>
  684. <row>
  685. <entry>MySQL (sync)</entry>
  686. <entry>35.86</entry>
  687. <entry>9461.10</entry>
  688. <entry>35.43</entry>
  689. <entry>36.11</entry>
  690. <entry>2392.12</entry>
  691. </row>
  692. <row>
  693. <entry>SQLite (sync)</entry>
  694. <entry>16.31</entry>
  695. <entry>67036.11</entry>
  696. <entry>16.76</entry>
  697. <entry>16.37</entry>
  698. <entry>16771.39</entry>
  699. </row>
  700. <row>
  701. <entry>memfile (sync)</entry>
  702. <entry>25.28</entry>
  703. <entry>3460207.61</entry>
  704. <entry>25.29</entry>
  705. <entry>25.43</entry>
  706. <entry>865070.90</entry>
  707. </row>
  708. </tbody>
  709. </tgroup>
  710. </table>
  711. <mediaobject>
  712. <imageobject>
  713. <imagedata fileref="performance-results-graph2.png" format="PNG"/>
  714. </imageobject>
  715. <textobject>
  716. <phrase>Optimized performance measurements</phrase>
  717. </textobject>
  718. <caption>
  719. <para>Graphical representation of the optimized performance
  720. results presented in table <xref linkend="tbl-optim-perf-results"
  721. />.</para>
  722. </caption>
  723. </mediaobject>
  724. </section>
  725. <section>
  726. <title>Conclusions</title>
  727. <para>
  728. Improvements gained by introducing support for precompiled
  729. statements in MySQL is somewhat disappointing - between 6 and
  730. 29%. On the other hand, the improvement in SQLite is
  731. surprisingly high - the efficiency is more than doubled.
  732. </para>
  733. <para>
  734. Compiled statements do not have any measureable impact on
  735. synchronous operations. That is as expected, because the major
  736. bottleneck is the disk performance.
  737. </para>
  738. <para>
  739. Compilation flags yield surprisingly high improvements for C++
  740. STL code. The memfile backend is in some operations is almost
  741. twice as fast.
  742. </para>
  743. <para>
  744. If synchronous operation is required, the current performance
  745. results are likely to be deemed inadequate. The limiting
  746. factor here is a disk access time. Even migrating to high
  747. performance 15,000 rpm disk is expected to only roughly double
  748. number of leases per second, compared to the current results.
  749. The reason is that to write a file to disk, at least two writes
  750. are required: the new content and i-node modification of the
  751. file. The easiest way to boost synchronous performance is to
  752. switch to SSD disks. Memory-backed RAM disks are also a viable
  753. solution. However, care should be taken to properly engineer
  754. backup strategy for RAM disks.
  755. </para>
  756. <para>
  757. While the custom made backend (memfile) provides the best
  758. perfomance, it carries over all the limitations existing in
  759. the ISC DHCP4 code: there are no external tools to query or
  760. change database, the maintenance requires deep knowledge etc.
  761. Those flaws are not shared by usage of a proper database
  762. backend, like MySQL and SQLite. They both offer third party
  763. tools for administrative tasks, they are well documented and
  764. maintained. However, SQLite support for concurrent access is
  765. limiting in certain cases. Since all three investigated
  766. backends more than meet expected performance results, it is
  767. recommended to use MySQL as a first concrete database backend.
  768. Should this choice be rejected for any reason, the second
  769. recommended choice is SQLite.
  770. </para>
  771. <para>
  772. It should be emphaisized that obtained measurements indicate
  773. only database performance and they cannot be directly
  774. translated to expected leases per second or queries per second
  775. performance by an actual server. The DHCP server must do much
  776. more than just query the database to properly process client's
  777. message. The provided results should be considered as only rough
  778. estimates. They can also be used for relative comparisons
  779. between backends.
  780. </para>
  781. </section>
  782. <section>
  783. <title>Possible further optimizations</title>
  784. <para>
  785. For basic measurements the code was compiled with -g -O0
  786. flags. For optimized measurements the benchmarking code was
  787. compiled with -Ofast (optimize for speed). In both cases, the
  788. same backend (MySQL or SQLite) library was used. It may be
  789. useful to recompile the libraries (or the whole server in case
  790. of MySQL) with -Ofast.
  791. </para>
  792. <para>
  793. There are many MySQL parameters that various sources recommend
  794. to improve performance. They were not investigated further.
  795. </para>
  796. <para>
  797. Currently all operations are conducted on one by one
  798. basis. Each operation is treated as a separate
  799. transaction. Grouping N operations together will potentially
  800. bring almost N fold increase in synchronous operations. Such a
  801. feature is present in ISC DHCP4 and is called cache-threshold.
  802. Extension for this benchmark in this regard should be
  803. considered. That affects only write operations (insert,
  804. update and delete). Read operations (search) are expected to
  805. be barely affected.
  806. </para>
  807. <para>
  808. Multi-threaded or multi-process benchmark may be considered in
  809. the future. It may be somewhat difficult as only some backends
  810. support concurrent access.
  811. </para>
  812. </section>
  813. </chapter>
  814. <chapter id="perfdhcp">
  815. <title>perfdhcp</title>
  816. <para>
  817. TODO: Write something about perfdhcp here.
  818. </para>
  819. </chapter>
  820. </book>