1
0
Fork 0
forked from mCaptcha/website
mcaptcha-website/blog/pow-performance/index.html

25 lines
13 KiB
HTML
Raw Normal View History

<!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.d731b24f97a905b851b9151339aca0f6a9b1c45ed16584cee7a4113d98d2a3db570c096603fbf15fbe9bbf092715cc742abaea351b4767239dbfedfffc08ebdb.css integrity="sha512-1zGyT5epBbhRuRUTOayg9qmxxF7RZYTO56QRPZjSo9tXDAlmA/vxX76bvwknFcx0KrrqNRtHZyOdv+3//Ajr2w==" 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-05-26T00:00:00+00:00"><meta property="article:modified_time" content="2021-09-01T14:27:17+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><a class=nav-link href=/about/>About</a></li><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=/docs/prologue/introduction/>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 May 26, 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 gives (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 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.db67f0caa6a5788b691b9509981d6e5943f4b8d829170a674f468d4b23671ce4017c47a0a22116a8fc2f2de556c8b48f1afecd86707066f2f022c5dd83e8ea3c.js integrity="sha512-22fwyqaleItpG5UJmB1uWUP0uNgpFwpnT0aNSyNnHOQBfEegoiEWqPwvLeVWyLSPGv7NhnBwZvLwIsXdg+jqPA==" crossorigin=anonymous defer></script><script src=/index.min.aab62a01bb69c52990d1e9a9072a01da2b9367f1a41ff3fa2b71ccdec4240b589f7196886485c3dd15f0598e76f83630d9f9432840f1758143eb96b263dcbe1e.js integrity="sha512-qrYqAbtpxSmQ0empByoB2iuTZ/GkH/P6K3HM3sQkC1ifcZaIZIXD3RXwWY52+DYw2flDKEDxdYFD65ayY9y+Hg==" crossorigin=anonymous defer></script></body></html>