鏁版嵁鍚屾鐨勪竴浜涙�濊�冧笌鏀硅繘

鏁版嵁鍚屾鐨勪竴浜涙�濊�冧笌鏀硅繘

鑳屾櫙

闂茬殑娌′簨,鑷繁鍐欎簡涓皬缃戠珯,鎼缓鍦ㄨ嚜宸卞浗澶栫殑VPS涓�,VPS鍐呭瓨鏋佸皬(512M),鑰屼笖杩樿璺戠偣鍒殑(浣犳噦鐨�),鍐呭瓨鏇寸揣寮犲反宸�. 鏀归�犱箣鍓嶅皬缃戠珯鐢ㄥ埌浜嗘椂楂︾殑Redis,Rabbmitmq,Mysql,閭f椂鍊欓樋閲屼簯鐨勫鐢熶富鏈哄唴瀛樺瘜瓒�,瑁呰繖涔堝涓棿浠跺帇鍔涗笉澶�,鍙埌浜嗚繖鏍风殑灏忓唴瀛榁PS涓�,涓�鍒囬兘鍙樺緱姘村湡涓嶆湇,绱㈡�у暐涓棿浠堕兘涓嶈浜�,鏁版嵁搴撲篃涓嶈浜�.
娌′簡鏁版嵁搴�,缃戠珯鐨勬暟鎹粠鍝噷鏉�?瀛樺湪鍝噷? 鏂囨湰褰㈠紡鎸佷箙鍖栧埌鏈湴纾佺洏?
鍥藉鐨刅PS涓嶆瘮鍥藉唴,鍙兘鍝ぉ璇翠笉鑳借闂氨涓嶈兘璁块棶浜�,VPS鐨勭鐩樺瓨鍌ㄦ樉鐒朵笉韪忓疄.
鍚屼簨缁欐垜寤鸿浜嗕竾鑳界殑Github,鍚繃Github鎵樼浠g爜馃摐,鎵樼闈欐�侀〉闈煍�,鎵樼濂宠澶т浆馃拑,浣嗘墭绠$綉绔欐暟鎹�掓槸绗竴娆″惉璇�,浜庢槸鎴戝缃戠珯鏋舵瀯杩涜浜嗛噸鏂拌璁�.

Plan1 鏁版嵁鐨勫悓姝�

鏁版嵁鍚屾鐨勪竴浜涙�濊�冧笌鏀硅繘_第1张图片

灏忕綉绔欐暟鎹笉澶�,10M宸﹀彸,鎵�鏈夋暟鎹洿鎺ュ姞杞藉埌鍐呭瓨涓湇鍔″櫒涔熶笉浼氬悆鍔�,缃戠珯鍚姩,鑷姩浠嶨ithub Clone鏁版嵁,骞跺畾鏈熸妸鍐呭瓨涓殑鏁版嵁搴忓垪鍖栧悗Push鍒癎ithub.
鍙互鐪嬪埌,鏁翠釜杩囩▼涓�,濂藉儚娌℃湁纾佺洏鍟ヤ簨浜�,鍦ㄦ垜鐨勭溂閲�,Github灏辨槸涓�鍧楀欢鏃剁暐楂樼殑纾佺洏(鍏跺疄寤舵椂涔熻繕濂�,鍥藉鐨凣ithub璁块棶閫熷害椋炲揩).

Plan2 鍚屾鐨勯鐜�

纾佺洏鐨勮鍙栭�熷害鍜屽唴瀛樻棤娉曟瘮,浣曞喌杩滅▼鐨凣ithub,閭d箞濡傛灉鍑忓皯鏁版嵁浠庡唴瀛樺埌Github鐨勫悓姝ュ紑閿�鍛�?鏄剧劧灏辨槸鍑忓皯鍚屾鐨勯鐜�.
涓�灏忔椂鍚屾涓�娆�,搴旇澶熶簡.
浣嗗鏋滄垜鐨勭綉绔欏湪杩欎竴灏忔椂鎸備簡boom馃寢,鑰屾暟鎹繕娌℃潵寰楀強鍚屾,閭d笂娆′竴鍚屾鍒扮綉绔欐寕鎺夎繖涓椂闂存鍐呯殑鏁版嵁涓嶅氨娌′簡鍚�?缁嗘�濇瀬鎭愷煒�!

Plan3 澶氬涓嶇泭鍠�

鏃㈢劧涓�灏忔椂涓�娆′笉瀹夊叏,閭e氨涓�鍒嗛挓鍚屾涓�娆�!
鍏跺疄杩欐牱涔熸槸鏈夐棶棰樼殑,灏忕綉绔欎竴鑸兘鏄棤浜洪棶娲�,濡傛灉浠ヨ緝楂樼殑棰戠巼杩涜鏁版嵁鍚屾,鍙互璇寸粷澶у鏁�(鐢ㄤ簰鑱旂綉鐨勬墍娉曟槸鐧惧垎涔婲涓�9)鐨勬暟鎹悓姝ラ兘鏄病鎰忎箟鐨�,鍚屾椂杩樺澶т簡鏁版嵁鐨勫悓姝ュ紑閿�,娌″噯Github杩樹細鎶婃垜鐨勮处鍙风粰灏佷簡.

Plan4 鍐呭瓨鏁版嵁鍙樻洿绔嬪嵆瑙﹀彂鏁版嵁鍚屾

鍦ㄦ垜鐨勭綉绔欎腑,鏈夌粺涓�鐨勬暟鎹闂眰,鍙鏁版嵁璁块棶灞備腑鐨刬nsert,update,delete澶勫姞鍏ユ暟鎹悓姝ヤ簨浠�,鍗冲彲瀹炵幇涓�鏃︽洿鏂扮珛鍗冲悓姝�.
杩欐牱鏄暟鎹槸瀹夊叏浜�,鍙槸涓�娆¤闂姹傚線寰�浼撮殢鐫�澶氭鏁版嵁鏇存柊,姣忔洿鏂颁竴娆″悓姝ヤ竴娆�,鍙兘鏄渶鑴戞畫馃檲鐨勫仛娉曞惂.

Question

鏁版嵁鏇存敼涓�娆″悓姝ヤ竴娆′笉鍚堢悊,鍚屾棰戠巼澶綆鏁版嵁涓嶅畨鍏�,棰戠巼澶珮澶氭暟鍚屾娌℃湁鎰忎箟,鍒板簳璇ユ�庢牱鍛�?

灞�閮ㄦ�у師鐞�

鍦ㄦ彮寮�鎴戠殑璁捐鏂规鍓�,鎴戜滑鍏堟潵杩囦竴涓婥PU璁块棶瀛樺偍鍣ㄦ椂鎵�閬靛畧鐨勫眬閮ㄦ�у師鐞�.

鍦ㄨ绠楁満瀛樺偍浠嬭川杩欎釜閲戝瓧濉斾腑,瓒婇潬杩戦噾瀛楀椤剁,绌洪棿瓒婂皬,浣嗘槸璇诲彇鏁版嵁瓒婂揩;瓒婇潬杩戦噾瀛楀搴曠,绌洪棿瓒婂ぇ,浣嗚闂�熷害涔熻秺鎱�.
姝e紡鍥犱负杩欐牱,鎵�浠ユ瘡娆¤嚜涓嬭�屼笂鐨勬暟鎹暟鎹祦澶у皬閫愬眰閫掑, 浜ゆ崲棰戠巼閫愬眰閫掑噺,濡備綍鍦ㄦ椂闂翠笌绌洪棿涓婂彇鍒板钩琛$偣鏄叧閿�.
浜庢槸鏈変簡绌洪棿灞�閮ㄦ�у師鐞嗗拰鏃堕棿灞�閮ㄦ�у師鐞�,鍔涙眰璁╄绠楁満鐨勬暟鎹祦鍔ㄦ洿楂樻晥.

鏁版嵁鍚屾鐨勪竴浜涙�濊�冧笌鏀硅繘_第2张图片

绌洪棿灞�閮ㄦ��

濡傛灉涓�鏉℃暟鎹璁块棶,閭d箞涓庡畠涓磋繎鐨勬暟鎹篃鍙兘瑕佽鐢ㄥ埌. 姣斿鏁扮粍,浣犺闂簡绱㈠紩1涓婄殑鏁版嵁,閭d箞1闄勮繎鐨勬暟鎹綋鐒跺緢鏈夊彲鑳借璁块棶,鎵�浠ヨ繖涓椂鍊欏共鑴嗘妸1闄勮繎鐨勬暟鎹篃寰�涓婂姞杞戒竴涓眰绾�.

鏃堕棿灞�閮ㄦ��

濡傛灉涓�鏉℃暟鎹」姝e湪琚闂紝閭d箞鍦ㄨ繎鏈熷畠寰堝彲鑳借繕浼氳鍐嶆璁块棶,鎵�浠ヨ繖涓椂鍊欏共鑴嗗氨鎶婂畠鐣欏湪褰撳墠灞傜骇,鍏堜笉鎬ョ潃鍥炴敹鎺�.

鑰岀綉绔欑殑鏁版嵁鐨勬洿鏂颁篃鏄叿鏈夋椂闂村眬閮ㄦ�х殑,鍍忔垜杩欐牱骞跺喎闂ㄧ殑缃戠珯,鍩烘湰娌′汉璁块棶,浣嗘槸涓�鏃﹁闂簡,绔嬪嵆灏辫杩涜鐐瑰嚮閲忕殑鏇存柊,绔欑偣鍝嶅簲閫熷害鐨勮褰�,娌″噯鍙堜細鏈夎瘎璁虹暀瑷�,鐒跺悗瑕侀�氱煡绠$悊鍛樿繘琛岀暀瑷�瀹℃牳.杩欏ぇ姒傚氨鏄笉楦e垯宸�,涓�楦f儕浜�,涓�娆¤闂煭鏈熷唴寰�寰�绔嬪嵆瑙﹀彂涓�杩炰覆鐨勬暟鎹洿鏂�,鎴戣涓鸿繖涔熸槸涓�绉嶆椂闂村眬閮ㄦ��.

鎵�浠�,鍦ㄦ暟鎹悓姝ヤ笂,鎴戣璁′簡濡備笅鏂规.

  • 鍙﹁捣涓�涓嚎绋嬩綔涓哄畾鏃朵换鍔�,涓昏璐熻矗瀹氭椂鏁版嵁鍚屾
  • 姝e父鎯呭喌涓�,姣忓皬鏃朵笌Github杩涜鏁版嵁鍚屾.
  • 涓�鏃︾綉绔欐暟鎹鏇存柊,妫�鏌ュ墿浣欏悓姝ユ椂闂存槸鍚﹀ぇ浜�30绉�.
    ** 濡傛灉澶т簬涓夊崄绉�,寮鸿鎶婅鏃跺櫒鍓╀綑鏃堕棿璁剧疆涓�30绉�.
    ** 濡傛灉灏忎簬涓夊崄绉�,涓嶅仛鎿嶄綔.
  • 璁℃椂鍣ㄦ椂闂磋蛋瀹�,绔嬪嵆鍚屾鏁版嵁鍒癎ithub.

瀹氭椂娌欐紡鈴�

鍘熸湰鏂囩珷璇村埌杩欓噷灏卞彲浠ョ粨鏉熶簡,浣嗙▼搴忓憳娉ㄥ畾鐖变唬鐮佺埍杩囨枃瀛�,鍙堟伆濂芥垜澶╃敓鐖遍�犺疆瀛�,鎴戜粠浠ょ墝妗跺緱鍒扮伒鎰熻璁′簡涓�涓篂涓愮増娌�婕忚鏃跺櫒,鍙互鐢ㄤ簬浠讳綍瀹氭椂浠诲姟鐨勬墽琛�,鐝棬寮勬枾,娆㈣繋鎻愬嚭鏀硅繘鎰忚.

Show time

public class BlogsTimer
{
    private static Stack _upFunnel;  //娌欐紡涓婇儴鍒�
    private static Stack _downFunnel;  //娌欐紡涓嬮儴鍒�
    private static readonly List TimerEvents;  //瀹氭椂鎵ц鐨勪簨浠�
    private static bool _timerSwitch;  //娌欐紡寮�鍏�
    private static readonly int Speed;  //姣忕娑堣垂浠ょ墝鏁伴噺
    private static Thread _timerThread;
    private static readonly object TimerLock;
    static BlogsTimer()
    {
        _upFunnel = new Stack();
        _downFunnel = new Stack();
        Speed = 1 * 1000;
        TimerEvents = new List();
        TimerLock = new object();
    }
    //璁℃椂鍣ㄥ紑濮�
    public static void Start(TimeSpan timeSpan)
    {
        lock (TimerLock)
        {
            _upFunnel.Clear();
            _downFunnel.Clear();
            for (var i = 0; i < timeSpan.TotalSeconds; i++)
            {
                _upFunnel.Push(i);
            }
        }
        _timerSwitch = true;
        _timerThread = new Thread(Consume); //璧蜂竴涓嚎绋嬫秷璐规《閲岀殑浠ょ墝
        _timerThread.Start();
        LunchEvents(); // 瑙﹀彂浜嬩欢
    }
    public static void Stop()
    {
        _timerSwitch = false;
    }

    //缁欐矙婕忔敞鍐屽畾鏃舵墽琛屼簨浠�
    public static void Register(Action timeEvent)
    {
        TimerEvents.Add(timeEvent);
        timeEvent.Invoke();
    }

    //鎶婃矙婕忓姞閫熷埌鎸囧畾鐨勬椂闂�
    public static void AccelerateTo(TimeSpan timeSpan)
    {
        var accelerateSeconds = timeSpan.TotalSeconds;
        lock (TimerLock)
        {
            if (_upFunnel.Count < accelerateSeconds) //褰撳墠娌欐紡涓墿浣欎护鐗屽皬浜庤缃腑绉掓暟,鍒欒繑鍥炰笉鍔犻��
                return;
            while (_upFunnel.Count > accelerateSeconds && _upFunnel.Count > 1)  //浠ょ墝鏁板ぇ浜庣鏁�,鍒欓噴鏀惧嚭澶氫綑浠ょ墝
            {
                _downFunnel.Push(_upFunnel.Pop());
            }
        }
    }
    private static void LunchEvents()
    {
        TimerEvents.ForEach(a => a.Invoke());
    }
    private static void Consume()
    {
        while (_timerSwitch)
        {
            lock (TimerLock)
            {
                if (_upFunnel.TryPop(out var item))
                {
                    _downFunnel.Push(item);
                }
                else
                {
                    LunchEvents();
                    var tempStack = _downFunnel;  //鏃嬭浆娌欐紡
                    _downFunnel = _upFunnel;
                    _upFunnel = tempStack;
                }
            }
            Thread.Sleep(Speed);
        }
    }
}

婧愮爜鍦板潃: https://github.com/liuzhenyulive/iBlogs/blob/master/Src/iBlogs.Site.Core/Common/iBlogsTimer.cs
婕旂ず鍦板潃: https://www.iblogs.site

你可能感兴趣的:(鏁版嵁鍚屾鐨勪竴浜涙�濊�冧笌鏀硅繘)