POW speed
Kagami opened this issue · 2 comments
Comparision of POW speed in different environments
Implementation sources: https://gist.github.com/Kagami/e15186b5d73224ca8c47
POW
target = 297422593171
initialHash = "8ff2d685db89a0af2e3dbfd3f700ae96ef4d9a1eac72fd778bbb368c7510cddda349e03207e1c4965bd95c6f7265e8f1a481a08afab3874eaafb9ade09a10880" (hex)
nonce = 21997550
trialValue = 120283692955
fastcpu (OpenSSL, 8 threads)
Run test POW for ~10-60 seconds, please be patient
Result nonce should be equal to 45833041
Done in 4.78248214722s: nonce = 21997550 with trial value 120283692955 < 297422593171 target
(5 seconds)
PyBitmessage (8 processes)
@@@ CALCULATE TARGET 297422593171 = 18446744073709551616 1000 628 8 1000 2418984 628 8 1000 65536
@@@ START AT: 1420638468
@@@ INPUT: 297422593171 8ff2d685db89a0af2e3dbfd3f700ae96ef4d9a1eac72fd778bbb368c7510cddda349e03207e1c4965bd95c6f7265e8f1a481a08afab3874eaafb9ade09a10880
@@@ END AT: 1420638483
@@@ RESULT: 120283692955 21997550
(15 seconds)
C (OpenSSL, 1 thread)
nonce = 21997550, trial = 120283692955 <= 297422593171 target
Resulting hash is: 0000001c01777f9bd7215852b3ff39ed5cd1b67ae81df304d05b136e38ae59330173f630fcf46665be38d5415d02ae48adcbea9bc8e29862c9888bcf22789308
./pow 19.28s user 0.00s system 99% cpu 19.278 total
(20 seconds)
JS (sha.js, 8 web workers)
Chrome
runPow()
undefined
index.browserify.js:17 pow: 132104.604ms
index.browserify.js:18 Result nonce: 21997550
(132 seconds, 2.25 minutes)
Firefox
pow: timer started index.browserify.js:5
pow: 230391.8ms index.browserify.js:17
"Result nonce: 21997550"
(230 seconds, 4 minutes)
JS (sha.js, 1 thread)
Chrome
runPow()
index.browserify.js:45 pow: 632656.147ms
21997550
(633 seconds, 10.5 minutes)
So it's pybitmessage = fastcpu*3
, c-singlethread = pybitmessage*1.5
, js-singlethread-chrome = pybitmessage*42
, js-workers-chrome = pybitmessage*9
.
Also, this example uses very simple nonce (22M dhashes), it's very common to have x2 and x4 nonces (30-60 seconds in PyBitmessge respectfully).
So, given this results, even simple POW are very hard to calculate in browser environment, even with fastest browser, fastest SHA-512 implementation and 8-core CPU.
The solution might be to calculate POW right on websocket relays which are required anyway. Given the fact that most cheap VPS only have 1 core available relays should use rather hard send limits. The average limit might be 1 message per 5 minutes for single client.
On the other hand, for TTL=86400
(1 day, 28 times smaller) results are rather appropriate:
Chrome (8 workers):
runPow()
undefined
index.browserify.js:17 pow: 19546.343ms
index.browserify.js:18 Result nonce: 3122437
(20 seconds)
Firefox (8 workers):
pow: timer started index.browserify.js:5
pow: 33294.94ms index.browserify.js:17
"Result nonce: 3122437" index.browserify.js:18
(33 seconds)
So using small ttls may be good enough for beta web client implementations. We may think how to handle it more gracefully later.