<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Aurélien Bottazini</title>
    <description>The latest articles on DEV Community by Aurélien Bottazini (@abottazini).</description>
    <link>https://dev.to/abottazini</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F828209%2F40bc4699-17e7-4b6f-a67d-fe9533f03eda.png</url>
      <title>DEV Community: Aurélien Bottazini</title>
      <link>https://dev.to/abottazini</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/abottazini"/>
    <language>en</language>
    <item>
      <title>Serve your data blazingly fast with Sqlite3 and Javascript</title>
      <dc:creator>Aurélien Bottazini</dc:creator>
      <pubDate>Sun, 16 Oct 2022 18:03:05 +0000</pubDate>
      <link>https://dev.to/abottazini/sqlite-performance-480b</link>
      <guid>https://dev.to/abottazini/sqlite-performance-480b</guid>
      <description>&lt;h1&gt;
  
  
  Serve your data blazingly fast with Sqlite3 and Javascript
&lt;/h1&gt;

&lt;p&gt;I love SQLite3. It is my de-facto database for personal projects. I have seen people import &lt;a href="https://blog.metaobject.com/2021/07/inserting-130m-sqlite-rows-per.html" rel="noopener noreferrer"&gt;millions of rows per minute&lt;/a&gt;. I was stunned to see it used as an &lt;a href="https://antonz.org/json-virtual-columns/" rel="noopener noreferrer"&gt;NOSQL Database&lt;/a&gt;. I adore that you can host SQLite databases &lt;a href="https://phiresky.github.io/blog/2021/hosting-sqlite-databases-on-github-pages/" rel="noopener noreferrer"&gt;everywhere&lt;/a&gt;. SQLite3 versatilety is amazing.&lt;/p&gt;

&lt;p&gt;I wanted to explore the performance of SQLite3 when it is used with a web server. Indeed with 2022 Europe energy crisis It is vital to find cost efficient solutions.&lt;/p&gt;

&lt;p&gt;I experimented with various programming languages: Go, Ruby, JavaScript, Rust. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;My goal: get a feel for what is achievable concurrency wise.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;I balanced speed with code complexity. I did not want to spend too much time on each implementation. The SQLite queries I used are simple. One insert statement, one query statement. This is not a test to verify SQLite performance. I know SQLite is fast. This is a test to see the blocking impact of SQLite queries on web servers.&lt;/p&gt;

&lt;p&gt;The JavaScript results amazed me.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;node&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;With an &lt;em&gt;sqlite insert&lt;/em&gt;: 16k requests per second&lt;/li&gt;
&lt;li&gt;With an &lt;em&gt;sqlite select&lt;/em&gt;: 31k requests per second&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc67jh1k9zeuhfc19oq7r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc67jh1k9zeuhfc19oq7r.png" alt="node-sqlite3" width="800" height="876"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;rust&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;With an &lt;em&gt;sqlite insert&lt;/em&gt;: 14k requests per second&lt;/li&gt;
&lt;li&gt;With an &lt;em&gt;sqlite select&lt;/em&gt;: 61k requests per second&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;rust&lt;/em&gt; is slower with inserts but twice as fast with queries.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsa4wn8rrqssnb0z3l3ti.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsa4wn8rrqssnb0z3l3ti.png" alt="rust sqlite3" width="800" height="892"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;bun.sh&lt;/strong&gt; (a new javascript runtime):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;With an &lt;em&gt;sqlite insert&lt;/em&gt;: 21k requests per second&lt;/li&gt;
&lt;li&gt;With an &lt;em&gt;sqlite select&lt;/em&gt;: 75k requests per second&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9u7sepajz9ez7mipgz2e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9u7sepajz9ez7mipgz2e.png" alt="bun.sh sqlite3" width="800" height="885"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What? &lt;em&gt;bun.sh&lt;/em&gt; is twice as fast on inserts and better on selects.&lt;br&gt;
We live in a time when anyone can serve tens of thousands of requests per second from one server (the one I used is 3 years old).&lt;br&gt;
You don't need a fancy database.&lt;br&gt;
An sqlite3 database hosted on the same host is more than enough.&lt;/p&gt;

&lt;p&gt;I remember hearing &lt;a href="https://www.youtube.com/watch?v=rczu8kc8JZA&amp;amp;t=35s" rel="noopener noreferrer"&gt;&lt;em&gt;John Carmack&lt;/em&gt; say&lt;/a&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The engineering under JavaScript is really pretty phenomenal
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;em&gt;bun.sh&lt;/em&gt; is a new example of phenomenal engineering for JavaScript.&lt;br&gt;
When you combine all the blazingly fast JavaScript optimisations with Sqlite3 you get performance that is on par with compiled languages.&lt;/p&gt;

&lt;p&gt;I imagine I could get &lt;em&gt;rust&lt;/em&gt; to be faster.&lt;br&gt;
But that's going to require more work to figure out the implementation details.&lt;br&gt;
&lt;em&gt;bun.sh&lt;/em&gt; + &lt;em&gt;SQLite3&lt;/em&gt; are more than enough for all my performance needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;John Carmack&lt;/em&gt; on Javascript: &lt;a href="https://www.youtube.com/watch?v=rczu8kc8JZA" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=rczu8kc8JZA&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="https://bun.sh/" rel="noopener noreferrer"&gt;bun.sh&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;blazingly fast like &lt;a href="https://www.twitch.tv/theprimeagen" rel="noopener noreferrer"&gt;ThePrimeagen&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;My test code: &lt;a href="https://github.com/aurelienbottazini/sqlite-performance-test" rel="noopener noreferrer"&gt;https://github.com/aurelienbottazini/sqlite-performance-test&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="https://blog.metaobject.com/2021/07/inserting-130m-sqlite-rows-per.html" rel="noopener noreferrer"&gt;Insert millions of rows per minute&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://antonz.org/json-virtual-columns/" rel="noopener noreferrer"&gt;SQLite as a NOSQL Database&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://phiresky.github.io/blog/2021/hosting-sqlite-databases-on-github-pages/" rel="noopener noreferrer"&gt;Host SQLite on Github pages&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>sqlite</category>
      <category>javascript</category>
      <category>rust</category>
      <category>webperf</category>
    </item>
  </channel>
</rss>
