经过一周时间修复了SteemMention的提醒延时问题

in #steem-mention7 years ago (edited)

SteemMention 是一个使用邮件接收 Steemit 回复提醒的工具,无需注册,只要有邮箱即可立即使用。

上周发布 到现在,SteemMention 整体运行平稳,不过我在运行的第一天就发现了一个比较严重的问题,就是用户收到提醒的时间会越来越晚。具体问题是怎么导致的呢?

先看一下第一版程序的同步脚本的核心思路图:

1.png

第一版的思路很简单,就是获取数据然后等待3秒,无限循环下去。这里问题出在了:我忽略了获取数据是属于高延时操作,且每次的执行时间是不定的,这就直接导致每个循环的执行时间远大于3秒

用户收到提醒的时间越来越慢,就是因为区块链数据每3秒更新一个区块,而我的同步程序每 (3+t[n]) 秒才拿到一个区块数据,其中 t[n] 是一个远大于1秒且不定的值。

经过一周对 Python 和 Python 中异步多线程的学习,我对程序做了很大的改动,如下图所示:

2.png

首先,程序使用了异步多线程的概念,其次就是每次获取数据改为了批量获取,即从上次结束的位置到最新位置之间的数据。

这样一来,创建支线任务的时间 t 是一个极小的值,且可以理解为每次操作的耗时是稳定的。同时由于每个支线任务是独立的,并不存在共享资源,主线程也不需要知道支线任务的执行结果,这样就可以让主线程的循环体执行时间稳定在3秒多一点。

另外,每次循环去获取批量数据,则是进一步修正了每个循环的时间在3秒多的问题。

新版本程序已经在2月5日14点更新了,目前几个小时的运行来看,效果不错。不过貌似多线程的操作是同步的,而不是异步的,目前完全靠批量获取来保证同步脚本能够跟上区块链数据更新。还需要继续看看 Python 的多线程任务。


感谢你的阅读,我是一个见证人,欢迎通过 SteemConnect 来给我投票。

Thank you for reading. I'm a witness. I would really appreciate your witness vote!
You can vote by SteemConnect.

steem.png
(图片制作于 Pix)

Sort:  

异步多线程不懂,不过总的还是懂了, 拜见高人!
ety是离我最近的见证人,因为大连有好多山东人,感觉是老乡一样,支持!

感谢支持~

This is the test for SteemMention.

Hy @ety001 I fan of your steemit. My level steemit is still low. Please help me to improve my steemit. Please vote my steemit only once. I hope you can help me. Please. Thanks
My steemit is @nauliquez

Hi my name is Ayudia Ningrum , vote me and follow

@steemitv

Congratulations! This post has been upvoted from the communal account, @minnowsupport, by ETY001 from the Minnow Support Project. It's a witness project run by aggroed, ausbitbank, teamsteem, theprophet0, someguy123, neoxian, followbtcnews, and netuoso. The goal is to help Steemit grow by supporting Minnows. Please find us at the Peace, Abundance, and Liberty Network (PALnet) Discord Channel. It's a completely public and open space to all members of the Steemit community who voluntarily choose to be there.

If you would like to delegate to the Minnow Support Project you can do so by clicking on the following links: 50SP, 100SP, 250SP, 500SP, 1000SP, 5000SP.
Be sure to leave at least 50SP undelegated on your account.

很牛。

This is test for SteemMention.

This is test for SteemMention. from liuye.

This is test for SteemMention. 2

This is test for SteemMention. 2

Coin Marketplace

STEEM 0.17
TRX 0.15
JST 0.029
BTC 61497.04
ETH 2478.29
USDT 1.00
SBD 2.66