每10分钟处理8M区块数据,相当于每秒处理13KB数据,这能撑爆屌丝电脑哪方面?CPU?内存?带宽?硬盘?
其实这是一个伪命题,因为有效节点需要24小时开机,个人电脑基本不会这样做干,但是可以就这个问题提供一些信息方便讨论:
一.这个8M的区块不是在10分钟内平均处理,资源占用曲线不是一条直线,所以不能相当于“每秒处理13KB数据”, 而是每隔10分钟处理8M数据,这需要在收到数据后马上处理所以实际的资源占用应该是一个波状曲线,电脑的资源占用每隔10分钟会有一个波峰起,但这也是理想状态
二. 我们来看看这8M数据需要处理什么,占用多少资源?
验证一个区块需要依赖很多东西:
1.软件版本 通常新的版本性能会高一些
2.UTXO 缓存的大小, 越大的缓存,访问硬盘上的数据库就越少,这会导致几毫秒到几秒的差异
3.签名缓存和cpu速度 ,越大的缓存,可以避免更多签名验证操作,签名验证在每个版本是不同的,每验证一个大约需要0.01ms~0.6ms,
验证一个区块的需要45ms ~ 2.7s
4. 内存池与新区块的关系,如果大部分交易在mempool中,验证区块将需要更少的时间
5. 网络延时,0.13以前的区块总是整个传输,当一个新区块产生时候需要占用不少资源
5. 和对端节点的网络延时,发送一个区块需要多次传输,和对端的延时会影响处理速度
6. 连接节点的数量,如果有多个连接,那么节点需要把新的区块广播到更多节点,将占用更多CPU和网络带宽资源
7. utxo的规模,初期utxo是很小的,当后来增长越来越大的时候会占用更多资源查询验证
8. 老版本的比特币代码签名验证存在一个效率低下的bug,即交易规模可能为O(n ^ 2)。这可能导致单个交易花费几分钟来计算签名散列。这在BIP144中得到了解决,BIP144总是在SegWit交易输入中使用,最坏的情况是O(n)(在最坏的情况下,对于普通硬件,小于10ms)。
然后看看真实的情况 一. @狙击手2113 举的例子是初始化下载,这个过程中会连续验证大量区块,当然这样会连续耗费大量系统资源,这普通人应该不能接受 这个就不讨论了
二. 假设区块已经同步完毕,再来看看收到区块号处理需要多少时间 在bitcoind运行的时候添加-debug=bench, 就会在debug.log里生成区块处理的时间记录
./bitcoind -debug=bench
debug.log 里会发现如下类似的记录:
2018-01-05 08:46:31 - Load block from disk: 0.00ms [0.00s]
2018-01-05 08:46:31 - Sanity checks: 0.00ms [0.00s]
2018-01-05 08:46:31 - Fork checks: 0.39ms [0.00s]
2018-01-05 08:46:31 - Connect 2519 transactions: 362.22ms (0.144ms/tx, 0.086ms/txin) [0.36s]
2018-01-05 08:46:31 - Verify 4205 txins: 362.37ms (0.086ms/txin) [0.36s]
2018-01-05 08:46:31 Pre-allocating up to position 0x700000 in rev01128.dat
2018-01-05 08:46:31 - Index writing: 11.97ms [0.01s]
2018-01-05 08:46:31 - Callbacks: 0.05ms [0.00s]
2018-01-05 08:46:31 - Connect total: 375.14ms [0.38s]
2018-01-05 08:46:31 - Flush: 10.05ms [0.01s]
2018-01-05 08:46:31 - Writing chainstate: 0.11ms [0.00s]
2018-01-05 08:46:34 UpdateTip: new best=00000000000000000086834f4afa2fde67a20b4fdedc27e778f3c510d8a8b854 height=502664 version =0x20000000 log2_work=87.80422 tx=289373815 date='2018-01-05 08:44:33' progress=0.999999 cache=19.6MiB(144282txo)
2018-01-05 08:46:34 - Connect postprocess: 2147.39ms [2.15s]
2018-01-05 08:46:34 - Connect block: 2532.70ms [2.53s]
其中最后这条就是总的处理时间
2018-01-05 08:46:34 - Connect block: 2532.70ms [2.53s]
前面就是各种检查,验证,cache, 写硬盘等等,总计2532.70ms,当然这个区块是比较长的
下面数据是在一台服务器生成的, 用的bitcoin 0.15分支,ssd硬盘,32G内存,8核cpu Intel(R) Xeon(R) CPU E5-2680 v3 @ 2.50GHz 抓了一点数据,从区块502664 ~ 502807
2018-01-05 08:46:34 - Connect block: 2532.70ms [2.53s]
2018-01-05 08:58:54 - Connect block: 139.53ms [2.67s]
2018-01-05 09:05:19 - Connect block: 176.13ms [2.85s]
2018-01-05 09:07:36 - Connect block: 272.23ms [3.12s]
2018-01-05 09:09:19 - Connect block: 189.65ms [3.31s]
2018-01-05 09:13:51 - Connect block: 214.62ms [3.52s]
2018-01-05 09:17:45 - Connect block: 203.60ms [3.73s]
2018-01-05 09:19:05 - Connect block: 335.54ms [4.06s]
2018-01-05 09:37:25 - Connect block: 135.15ms [4.20s]
2018-01-05 09:47:10 - Connect block: 94.84ms [4.29s]
2018-01-05 09:47:37 - Connect block: 99.03ms [4.39s]
2018-01-05 09:57:17 - Connect block: 111.59ms [4.50s]
2018-01-05 10:33:57 - Connect block: 100.12ms [4.60s]
2018-01-05 10:34:04 - Connect block: 106.79ms [4.71s]
2018-01-05 10:41:31 - Connect block: 97.01ms [4.81s]
2018-01-05 10:42:03 - Connect block: 103.70ms [4.91s]
2018-01-05 11:22:08 - Connect block: 97.24ms [5.01s]
2018-01-05 11:25:23 - Connect block: 113.08ms [5.12s]
2018-01-05 11:36:11 - Connect block: 108.54ms [5.23s]
2018-01-05 11:38:24 - Connect block: 98.62ms [5.33s]
2018-01-05 11:45:35 - Connect block: 290.71ms [5.62s]
2018-01-05 11:48:54 - Connect block: 250.84ms [5.87s]
2018-01-05 11:55:22 - Connect block: 362.05ms [6.23s]
2018-01-05 12:06:08 - Connect block: 108.19ms [6.34s]
2018-01-05 12:08:50 - Connect block: 263.63ms [6.61s]
2018-01-05 12:29:27 - Connect block: 428.03ms [7.03s]
2018-01-05 12:43:41 - Connect block: 943.21ms [7.98s]
2018-01-05 12:44:58 - Connect block: 116.12ms [8.09s]
2018-01-05 12:52:22 - Connect block: 98.15ms [8.19s]
2018-01-05 13:04:52 - Connect block: 116.28ms [8.31s]
2018-01-05 13:15:34 - Connect block: 331.70ms [8.64s]
2018-01-05 13:28:30 - Connect block: 185.83ms [8.82s]
2018-01-05 13:36:25 - Connect block: 302.89ms [9.13s]
2018-01-05 13:42:03 - Connect block: 81.50ms [9.21s]
2018-01-05 13:50:58 - Connect block: 70.95ms [9.28s]
2018-01-05 14:12:27 - Connect block: 73.40ms [9.35s]
2018-01-05 14:22:13 - Connect block: 77.62ms [9.43s]
2018-01-05 14:26:32 - Connect block: 394.93ms [9.83s]
2018-01-05 14:33:17 - Connect block: 73.67ms [9.90s]
2018-01-05 14:52:27 - Connect block: 72.17ms [9.97s]
2018-01-05 15:27:53 - Connect block: 2148.74ms [2.15s]
2018-01-05 15:41:51 - Connect block: 104.38ms [2.25s]
2018-01-05 15:46:35 - Connect block: 91.57ms [2.34s]
2018-01-05 15:54:48 - Connect block: 88.23ms [2.43s]
2018-01-05 15:57:49 - Connect block: 94.94ms [2.53s]
2018-01-05 16:03:20 - Connect block: 145.27ms [2.67s]
2018-01-05 16:03:40 - Connect block: 96.68ms [2.77s]
2018-01-05 16:07:37 - Connect block: 92.15ms [2.86s]
2018-01-05 16:33:01 - Connect block: 75.64ms [2.94s]
2018-01-05 16:38:44 - Connect block: 69.83ms [3.01s]
2018-01-05 16:39:29 - Connect block: 85.15ms [3.09s]
2018-01-05 16:46:24 - Connect block: 70.07ms [3.16s]
2018-01-05 16:47:48 - Connect block: 89.63ms [3.25s]
2018-01-05 16:57:22 - Connect block: 79.59ms [3.33s]
2018-01-05 17:00:42 - Connect block: 74.84ms [3.41s]
2018-01-05 17:04:45 - Connect block: 87.91ms [3.49s]
2018-01-05 17:06:10 - Connect block: 92.97ms [3.59s]
2018-01-05 17:10:46 - Connect block: 88.91ms [3.68s]
2018-01-05 17:15:12 - Connect block: 67.22ms [3.74s]
2018-01-05 17:26:54 - Connect block: 77.37ms [3.82s]
2018-01-05 17:33:23 - Connect block: 65.43ms [3.89s]
2018-01-05 17:38:08 - Connect block: 69.34ms [3.96s]
2018-01-05 17:59:04 - Connect block: 72.14ms [4.03s]
2018-01-05 18:09:56 - Connect block: 73.71ms [4.10s]
2018-01-05 18:11:24 - Connect block: 72.10ms [4.17s]
2018-01-05 18:14:50 - Connect block: 77.95ms [4.25s]
2018-01-05 18:27:03 - Connect block: 76.83ms [4.33s]
2018-01-05 18:32:16 - Connect block: 81.21ms [4.41s]
2018-01-05 18:48:59 - Connect block: 75.84ms [4.49s]
2018-01-05 19:03:47 - Connect block: 77.86ms [4.56s]
2018-01-05 19:11:18 - Connect block: 79.90ms [4.64s]
2018-01-05 19:23:34 - Connect block: 72.16ms [4.72s]
2018-01-05 19:44:54 - Connect block: 71.59ms [4.79s]
2018-01-05 19:45:50 - Connect block: 95.71ms [4.88s]
2018-01-05 20:01:16 - Connect block: 76.38ms [4.96s]
2018-01-05 20:24:48 - Connect block: 72.82ms [5.03s]
2018-01-05 20:38:30 - Connect block: 78.33ms [5.11s]
2018-01-05 20:52:29 - Connect block: 76.22ms [5.19s]
2018-01-05 21:00:02 - Connect block: 85.11ms [5.27s]
2018-01-05 21:02:23 - Connect block: 69.26ms [5.34s]
2018-01-05 21:08:56 - Connect block: 78.06ms [5.42s]
2018-01-05 21:41:32 - Connect block: 71.23ms [5.49s]
2018-01-05 21:54:17 - Connect block: 75.79ms [5.57s]
2018-01-05 22:07:33 - Connect block: 70.95ms [5.64s]
2018-01-05 22:45:49 - Connect block: 71.13ms [5.71s]
2018-01-05 23:02:05 - Connect block: 77.69ms [5.79s]
2018-01-05 23:02:30 - Connect block: 90.44ms [5.88s]
2018-01-05 23:03:13 - Connect block: 79.05ms [5.96s]
2018-01-05 23:18:31 - Connect block: 66.09ms [6.02s]
2018-01-05 23:22:10 - Connect block: 79.78ms [6.10s]
2018-01-05 23:28:47 - Connect block: 72.75ms [6.17s]
2018-01-05 23:28:47 - Connect block: 82.79ms [6.26s]
2018-01-05 23:59:46 - Connect block: 75.39ms [6.33s]
2018-01-06 00:02:52 - Connect block: 78.58ms [6.41s]
2018-01-06 00:17:43 - Connect block: 75.23ms [6.49s]
2018-01-06 00:28:13 - Connect block: 80.44ms [6.57s]
2018-01-06 00:52:00 - Connect block: 100.88ms [6.67s]
2018-01-06 00:54:51 - Connect block: 87.12ms [6.75s]
2018-01-06 00:59:57 - Connect block: 78.43ms [6.83s]
2018-01-06 01:17:52 - Connect block: 92.19ms [6.93s]
2018-01-06 01:36:12 - Connect block: 117.87ms [7.04s]
2018-01-06 01:45:07 - Connect block: 70.66ms [7.11s]
2018-01-06 01:51:36 - Connect block: 89.60ms [7.20s]
2018-01-06 01:53:22 - Connect block: 79.21ms [7.28s]
2018-01-06 02:05:38 - Connect block: 90.48ms [7.37s]
2018-01-06 02:06:42 - Connect block: 112.38ms [7.49s]
2018-01-06 02:12:37 - Connect block: 71.84ms [7.56s]
2018-01-06 02:18:03 - Connect block: 75.82ms [7.63s]
2018-01-06 02:25:26 - Connect block: 80.17ms [7.71s]
2018-01-06 02:25:47 - Connect block: 135.73ms [7.85s]
2018-01-06 02:35:43 - Connect block: 105.62ms [7.95s]
2018-01-06 02:38:39 - Connect block: 98.60ms [8.05s]
2018-01-06 02:40:45 - Connect block: 161.57ms [8.21s]
2018-01-06 03:08:44 - Connect block: 78.00ms [8.29s]
2018-01-06 03:17:53 - Connect block: 76.59ms [8.37s]
2018-01-06 03:26:21 - Connect block: 69.61ms [8.44s]
2018-01-06 04:08:09 - Connect block: 72.50ms [8.51s]
2018-01-06 04:08:27 - Connect block: 76.52ms [8.59s]
2018-01-06 04:08:49 - Connect block: 80.24ms [8.67s]
2018-01-06 04:12:32 - Connect block: 129.10ms [8.80s]
2018-01-06 04:14:19 - Connect block: 87.78ms [8.88s]
2018-01-06 04:19:25 - Connect block: 120.86ms [9.01s]
2018-01-06 04:20:25 - Connect block: 164.79ms [9.17s]
2018-01-06 04:23:56 - Connect block: 245.29ms [9.42s]
2018-01-06 04:24:50 - Connect block: 327.44ms [9.74s]
2018-01-06 04:28:17 - Connect block: 250.22ms [9.99s]
2018-01-06 04:38:17 - Connect block: 388.64ms [10.38s]
2018-01-06 04:44:30 - Connect block: 250.66ms [10.63s]
2018-01-06 05:02:32 - Connect block: 108.86ms [10.74s]
2018-01-06 05:15:35 - Connect block: 84.31ms [10.83s]
2018-01-06 05:16:11 - Connect block: 586.11ms [11.41s]
2018-01-06 05:26:30 - Connect block: 288.76ms [11.70s]
2018-01-06 05:29:48 - Connect block: 56.41ms [11.76s]
2018-01-06 06:04:00 - Connect block: 84.79ms [11.84s]
2018-01-06 06:04:36 - Connect block: 113.70ms [11.96s]
2018-01-06 06:27:45 - Connect block: 80.85ms [12.04s]
2018-01-06 06:32:36 - Connect block: 86.82ms [12.12s]
2018-01-06 06:40:21 - Connect block: 282.38ms [12.41s]
2018-01-06 06:42:07 - Connect block: 497.73ms [12.90s]
2018-01-06 06:46:46 - Connect block: 2429.33ms [15.33s]
2018-01-06 06:46:46 - Connect block: 1.74ms [15.33s]
2018-01-06 06:50:54 - Connect block: 7089.67ms [22.42s]
2018-01-06 06:55:26 - Connect block: 4698.15ms [27.12s]
2018-01-06 06:58:33 - Connect block: 288.08ms [27.41s]
2018-01-06 07:05:42 - Connect block: 982.20ms [28.39s]
汇总得到的数据,
block number 145 avg 264.581034ms, min 1.740000ms, max 7089.670000ms
假如区块增大8倍,假设处理时间也线性增长
8M: block number 145 avg 2116.648276ms, min 13.920000ms, max 56717.360000ms
另外注意这是一个节点的验证时间,还有因为区块传输可能需要跨越多个节点,假设一个区块一个节点验证需要1分钟,考虑到网络延时,那么10分钟内8M的区块最多跨越10个节点,这样会会导致极端情况下,节点会连续收到多个区块,如果普通用户的cpu被连续100%占用几分钟,那应该是不可接受的,当然这个数据并不严谨,只是举个例子
Jameson Lopp 在这里记录了他自己服务器的使用情况,因为还有网站什么在跑,不是很准确,但可以用来参考
cpu、内存、硬盘的使用情况 http://statoshi.info/dashboard/db/system-metrics
网络使用情况 http://statoshi.info/dashboard/db/bandwidth-usage
网友评论