继续昨天有意思的话题,在前文中,我们总算研究明白了如何计算全网的总带宽/max_virtual_bandwidth,但是正如我在那篇文章开头介绍的,我的目的是为了计算用户可用带宽百分比。那么接下来我们就要研究一下如何计算可用带宽以及百分比。
(图源 :pixabay)
用户分配带宽
前文中我们贴出了用户可用带宽的计算方式:
变换后的公式为:
用户分配带宽 = account_vshares / total_vshares* max_virtual_bandwidth
这里边最麻烦的是max_virtual_bandwidth
,我们已经在上文搞定了,所以计算用户分配到的带宽没有什么难度。
用户平均带宽
在这篇文章中我们分析过平均带宽的概念
你可能说了,我好多天没发帖,发了一个帖子占用 5K Bandwidth,别人每天发帖,每个帖子占用1K,那怎么衡量谁占的多啊,谁占的少啊?
很好的问题,STEEM为了防止这种情况,引入了
平均带宽Average Bandwidth
的概念。
Average Bandwidth 以7天为时间窗计算的方式为:
(7天 - 距离上次操作的时间)*之前的Average Bandwidth/7天 + 本次操作Bandwidth
(如果距离上次操作时间 > 7天,则新的Average Bandwidth 为 本次操作Bandwidth)
代码:
所以为了计算用户的平均带宽,除了代码中那些常量,我们还需要知道上次带宽更新的时间
以及用户之前的平均带宽
也就是类似如下信息:
'average_bandwidth': '117344254786',
'last_bandwidth_update': '2018-01-25T10:35:06',
这有点像voting power, 我们可以用get_account()
读出voting power
,但是这个值不是实时的,我们需要用当前时间以及上次计算的时间去修正这个值。
用户可用带宽
知道用户分配的带宽以及用户平均带宽之后,那么可用带宽就容易计算了
用户可用带宽 = 用户分配的带宽 - 用户平均带宽
带宽百分比计算也很容易啦:
用户可用带宽 / 用户分配的带宽 * 100%
带宽变换成字节数
上述计算可用带宽还是平均带宽都是一个很大的数值,你可能会好奇,这个值具体是啥意思呢?如果转换成字节应该会比较明了了。
这涉及到另外一个参数STEEMIT_BANDWIDTH_PRECISION
,把我们得到数值除以这个精度就是字节数啦。
至此,我们可以拿到和带宽相关的所有数据啦。
测试一下,我的可用带宽充裕着呢
总结
好像也没啥需要总结的,大概需要记住以下亮点吧
- 用户
average_bandwidth
需要用时间去修正 - 带宽除以
STEEMIT_BANDWIDTH_PRECISION
可以得到带宽的字节数表示
另外,有人问我: 可用带宽如何才能充裕?答案就是充值STEEM POWER.
连着一周,无论我是一天就发一篇还是两篇,到了晚上就提示我带宽不足,昨天因为一直在外面跑,其实都没怎么看帖子也么有回复,很忧伤。
看到这个“引入了平均带宽Average Bandwidth的概念。Average Bandwidth 以7天为时间窗”,大概可以理解成这一周操作(zuo nie)太多了的结果吧,sp太少果然还是硬伤
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
其实很简单,在内部市场使用sbd购买一些steem
然后power up
就搞定啦;)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
嘿嘿,看到最后一句就get到啦,谢谢o哥回复^ω^
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
还是没看懂怎么回事。
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
I wish that was in English, I run out of bandwidth every day, is someone working on a solution to that?
Is that happening to other people?
How much SP do I need before that does not happen anymore?
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
yes
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Nice post.I respect you very much because you contribute to steemit.I will do activities like you.I would like to extend the steemit.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Oh i wish you put the english version. This is something i'd like to know
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
5000 followers Congratulation
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
@oflyhigt ,,,,,,I totally agree with your thoughts
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
I have no idea what you said but it looks cool
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
o神总算介绍这个了,我每天晚上9点半,准时限速。
先收藏后看!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Good work,i liked you are work,kindly visit my blog.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
good
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
bagus bagus
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
ok
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit