website/blog/pow-performance/index.html

25 lines
14 KiB
HTML

<!doctype html><html lang=en-us><head><meta charset=utf-8><meta http-equiv=x-ua-compatible content="ie=edge"><meta name=viewport content="width=device-width,initial-scale=1,shrink-to-fit=no"><link rel=preload as=font href=/fonts/vendor/jost/jost-v4-latin-regular.woff2 type=font/woff2 crossorigin><link rel=preload as=font href=/fonts/vendor/jost/jost-v4-latin-700.woff2 type=font/woff2 crossorigin><link rel=stylesheet href=/main.f4e82f75f039986a07346a99687f11e3218d588abe9b9daa7d0673b1a7aaee5b689ec69619c26a2962d5a124bed33807d58bd84180c249bbb8eddc33c5ef5baa.css integrity="sha512-9OgvdfA5mGoHNGqZaH8R4yGNWIq+m52qfQZzsaeq7ltonsaWGcJqKWLVoSS+0zgH1YvYQYDCSbu47dwzxe9bqg==" crossorigin=anonymous><noscript><style>img.lazyload{display:none}</style></noscript><meta name=robots content="index, follow"><meta name=googlebot content="index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1"><meta name=bingbot content="index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1"><title>PoW performance - mCaptcha</title><meta name=description content="PoW performance of native and WASM implementations. Does the native implementation have and edge over the WASM library?"><link rel=canonical href=/blog/pow-performance/><meta name=twitter:card content="summary_large_image"><meta name=twitter:image content="/blog/pow-performance/icon.png"><meta name=twitter:title content="PoW performance"><meta name=twitter:description content="PoW performance of native and WASM implementations. Does the native implementation have and edge over the WASM library?"><meta name=twitter:site content="@"><meta name=twitter:creator content="@"><meta property="og:title" content="PoW performance"><meta property="og:description" content="PoW performance of native and WASM implementations. Does the native implementation have and edge over the WASM library?"><meta property="og:type" content="article"><meta property="og:url" content="/blog/pow-performance/"><meta property="og:image" content="/blog/pow-performance/icon.png"><meta property="article:published_time" content="2021-09-01T00:00:00+00:00"><meta property="article:modified_time" content="2021-09-01T15:33:12+05:30"><meta property="og:site_name" content="mCaptcha"><meta property="article:publisher" content="https://www.facebook.com/"><meta property="article:author" content="https://www.facebook.com/"><meta property="og:locale" content="en_US"><script type=application/ld+json>{"@context":"http://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"\/"},{"@type":"ListItem","position":2,"name":"Blogpow Performance","item":"\/blogpow-performance\/"}]}</script><meta name=theme-color content="#fff"><link rel=apple-touch-icon sizes=180x180 href=/apple-touch-icon.png><link rel=icon type=image/png sizes=32x32 href=/favicon-32x32.png><link rel=icon type=image/png sizes=16x16 href=/favicon-16x16.png><link rel=manifest href=/site.webmanifest></head><body class="blog single"><div class="header-bar fixed-top"></div><header class="navbar fixed-top navbar-expand-md navbar-light"><div class=container><input class="menu-btn order-0" type=checkbox id=menu-btn>
<label class="menu-icon d-md-none" for=menu-btn><span class=navicon></span></label><a class="navbar-brand order-1 order-md-0 me-auto" href=/>mCaptcha</a>
<button id=mode class="btn btn-link order-2 order-md-4" type=button aria-label="Toggle mode">
<span class=toggle-dark><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentcolor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-moon"><path d="M21 12.79A9 9 0 1111.21 3 7 7 0 0021 12.79z"/></svg></span><span class=toggle-light><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentcolor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-sun"><circle cx="12" cy="12" r="5"/><line x1="12" y1="1" x2="12" y2="3"/><line x1="12" y1="21" x2="12" y2="23"/><line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/><line x1="1" y1="12" x2="3" y2="12"/><line x1="21" y1="12" x2="23" y2="12"/><line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/><line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/></svg></span></button><ul class="navbar-nav social-nav order-3 order-md-5"><li class=nav-item><a class=nav-link href=https://github.com/mCaptcha><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentcolor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-github"><path d="M9 19c-5 1.5-5-2.5-7-3m14 6v-3.87a3.37 3.37.0 00-.94-2.61c3.14-.35 6.44-1.54 6.44-7A5.44 5.44.0 0020 4.77 5.07 5.07.0 0019.91 1S18.73.65 16 2.48a13.38 13.38.0 00-7 0C6.27.65 5.09 1 5.09 1A5.07 5.07.0 005 4.77 5.44 5.44.0 003.5 8.55c0 5.42 3.3 6.61 6.44 7A3.37 3.37.0 009 18.13V22"/></svg><span class="ms-2 visually-hidden">GitHub</span></a></li></ul><div class="collapse navbar-collapse order-4 order-md-1"><ul class="navbar-nav main-nav me-auto order-5 order-md-2"><li class="nav-item active"><a class=nav-link href=/blog/>Blog</a></li><li class=nav-item><a class=nav-link href=/community/>Community</a></li><li class=nav-item><a class=nav-link href=/contact/>Contact</a></li><li class=nav-item><a class=nav-link href=/about/>About</a></li><li class=nav-item><a class=nav-link href=/docs/introduction/installing-captcha/>Docs</a></li></ul><div class="break order-6 d-md-none"></div><form class="navbar-form flex-grow-1 order-7 order-md-3"><input id=userinput class="form-control is-search" type=search placeholder="Search docs..." aria-label="Search docs..." autocomplete=off><div id=suggestions class="shadow bg-white rounded"></div></form></div></div></header><div class="wrap container" role=document><div class=content><div class="row flex-xl-nowrap"><nav class="docs-toc d-none d-xl-block col-xl-3" aria-label="Secondary navigation"><div class=page-links><h3>On this page</h3><nav id=TableOfContents><ul><li><a href=#benchmark-tools>Benchmark tools</a></li><li><a href=#results>Results</a><ul><li><a href=#native>Native</a></li><li><a href=#browser>Browser</a></li><li><a href=#firefox>Firefox</a></li></ul></li><li><a href=#conclusion>Conclusion</a></li></ul></nav></div></nav><main class="docs-content col-lg-11 col-xl-9 mx-xl-auto"><article><div class=blog-header><h1>PoW performance</h1><p><small>Posted September 1, 2021 by <a class="stretched-link position-relative" href=/contributors/aravinth-manivannan/>Aravinth Manivannan</a>&nbsp;&dash;&nbsp;<strong>2&nbsp;min read</strong></small><p><p><small>Last Edited September 1, 2021</small><p></div><p class=lead>We are mCaptcha. We build kickass CAPTCHA systems that give (DDoS) attackers a run for their money. And we do all of this without tracking your users. Oh and did I mention our UX is great?</p><p>mCaptcha uses a
<a href=https://en.wikipedia.org/wiki/Proof_of_work>proof-of-work(PoW)</a> mechanism
to rate limit users or potential bots. In order for this to be
effective, the PoW should be configured properly. The difficulty
requirement can&rsquo;t be too high, as it could cause accessibility issues on
the client-side while at the same time, it shouldn&rsquo;t be too low, as it
wouldn&rsquo;t offer proper protection against bots.</p><p>Malicious bots(the ones that wreak havoc), run native code which is
capable of running in a multi-threaded context. This creates an unfair
advantage for crackers using these bots over legitimate users, who
usually use browsers to access a website.</p><p>I wanted to see how much of an advantage a native program would have
over our WASM library.</p><h2 id=benchmark-tools>Benchmark tools</h2><p>So I wrote these to compare native and WASM performances:</p><ul><li>Browser benchmark: <a href=https://mCaptcha.github.io/benches>https://mCaptcha.github.io/benches</a></li><li>Native benchmark: <a href=https://github.com/mCaptcha/cli/blob/master/scripts/bench.sh>mCaptcha/cli managed by scripts/bench.sh</a></li></ul><div class="alert alert-warning d-flex" role=alert><div class="flex-shrink-1 alert-icon"></div><div class=w-100>Feel free to reproduce the results!</div></div><h2 id=results>Results</h2><p>The tests were run on my development machine featuring an Intel Core
i7-9750h.</p><h3 id=native>Native</h3><table><thead><tr><th>Difficulty</th><th>Real</th><th>User</th><th>Sys</th></tr></thead><tbody><tr><td>500000</td><td>0m0.220s</td><td>0m0.197s</td><td>0m0.006s</td></tr><tr><td>1000000</td><td>0m0.203s</td><td>0m0.203s</td><td>0m0.000s</td></tr><tr><td>1500000</td><td>0m0.198s</td><td>0m0.198s</td><td>0m0.000s</td></tr><tr><td>2000000</td><td>0m0.203s</td><td>0m0.203s</td><td>0m0.000s</td></tr><tr><td>2500000</td><td>0m0.758s</td><td>0m0.752s</td><td>0m0.003s</td></tr><tr><td>3000000</td><td>0m0.776s</td><td>0m0.769s</td><td>0m0.003s</td></tr><tr><td>3500000</td><td>0m2.010s</td><td>0m1.998s</td><td>0m0.000s</td></tr><tr><td>4000000</td><td>0m2.038s</td><td>0m2.033s</td><td>0m0.003s</td></tr><tr><td>4500000</td><td>0m2.014s</td><td>0m2.013s</td><td>0m0.000s</td></tr></tbody></table><h3 id=browser>Browser</h3><p>I ran the tests on both Firefox and Chromium to compare results</p><h3 id=firefox>Firefox</h3><ul><li><strong>User Agent:</strong> <code>Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0</code></li><li><strong>Hardware concurrency:</strong> 12</li></ul><table><thead><tr><th>Difficulty</th><th>Duration(in ms)</th></tr></thead><tbody><tr><td>500000</td><td>401</td></tr><tr><td>1000000</td><td>413</td></tr><tr><td>1500000</td><td>398</td></tr><tr><td>2000000</td><td>394</td></tr><tr><td>2500000</td><td>1495</td></tr><tr><td>3000000</td><td>1556</td></tr><tr><td>3500000</td><td>3971</td></tr><tr><td>4000000</td><td>4235</td></tr><tr><td>4500000</td><td>4116</td></tr></tbody></table><blockquote><p>To be fair, my Firefox installation is loaded with a gazillion
extensions while the Chromium instance is clean, as I don&rsquo;t use it
much</p></blockquote><h4 id=chromium>Chromium</h4><ul><li><strong>User Agent:</strong> <code>Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36</code></li><li><strong>Hardware concurrency:</strong> 12</li></ul><table><thead><tr><th>Difficulty</th><th>Duration(in ms)</th></tr></thead><tbody><tr><td>500000</td><td>399.40000000037253</td></tr><tr><td>1000000</td><td>354.6000000014901</td></tr><tr><td>1500000</td><td>351.19999999925494</td></tr><tr><td>2000000</td><td>353.80000000074506</td></tr><tr><td>2500000</td><td>1337.800000000745</td></tr><tr><td>3000000</td><td>1311.199999999255</td></tr><tr><td>3500000</td><td>3417.5999999996275</td></tr><tr><td>4000000</td><td>3488.800000000745</td></tr><tr><td>4500000</td><td>3458.2999999988824</td></tr></tbody></table><h2 id=conclusion>Conclusion</h2><p>At the highest difficulty factor, the native implementation was a almost second
faster than the WASM library. But the fact that both of them were able
to run to completion in under 5 seconds is impressive!</p><p>So, in my opinion, native implementation is only slightly faster than
the WASM library and for all intents and purposes, this shouldn&rsquo;t matter
much.</p><hr><p>P.S Work is underway to benchmark multiple platforms. A detailed report
will be published when that data is available.</p><p>For this post, I asked some of my friends to run the tests on their
computers. The results slightly varied but even the slowest case
generated proof for 4500000 difficulty(the highest in this test), in under
15 seconds!</p></article><div class="docs-navigation d-flex justify-content-between"><a href=/blog/survey/><div class="card my-1"><div class="card-body py-2">&larr; Survey</div></div></a><a class=ms-auto href=/blog/say-hello-to-mcaptcha/><div class="card my-1"><div class="card-body py-2">Say hello to mCaptcha &rarr;</div></div></a></div><p class=edit-page><a href=https://github.com/mCaptcha/website/blob/master/content/blog/pow-performance/index.md><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentcolor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-edit-2"><path d="M17 3a2.828 2.828.0 114 4L7.5 20.5 2 22l1.5-5.5L17 3z"/></svg>Edit this page on GitHub</a></p></main></div></div></div><footer class="footer text-muted"><div class=container><div class=row><div class="col-lg-8 order-last order-lg-first"><ul class=list-inline><li class=list-inline-item>Powered by <a href=https://gohugo.io/>Hugo</a>, and <a href=https://getdoks.org/>Doks</a></li></ul></div><div class="col-lg-8 order-first order-lg-last text-lg-end"><ul class=list-inline><li class=list-inline-item><a href=/about/>About</a></li><li class=list-inline-item><a href=/donate>Donate</a></li><li class=list-inline-item><a href=/privacy-policy/>Privacy</a></li><li class=list-inline-item><a href=/security>Security</a></li><li class=list-inline-item><a href=https://stats.uptimerobot.com/GK7VLFJnBl>Status</a></li><li class=list-inline-item><a href=/thanks>Thanks</a></li></ul></div></div></div></footer><script src=/main.min.993b2b4c58b07e7a4bb3423cf18ccd78a85d0063680c0fc9bf6d9cc02be98e08793034d984dd8f7c60ad5b70f3186cc8bc280b1077b7e37c2d64f36f118099bb.js integrity="sha512-mTsrTFiwfnpLs0I88YzNeKhdAGNoDA/Jv22cwCvpjgh5MDTZhN2PfGCtW3DzGGzIvCgLEHe343wtZPNvEYCZuw==" crossorigin=anonymous defer></script><script src=/index.min.9f6ca8d18a9feb4c8173940752baf80e8075b025ffbfcec12016beb0c2f8f794667102d45eb9accca8c374b0dd7a69af667e0f20813fb4fb086e6cda5230e2d8.js integrity="sha512-n2yo0Yqf60yBc5QHUrr4DoB1sCX/v87BIBa+sML495RmcQLUXrmszKjDdLDdemmvZn4PIIE/tPsIbmzaUjDi2A==" crossorigin=anonymous defer></script></body></html>