鏁版嵁鍚屾鐨勪竴浜涙�濊�冧笌鏀硅繘
鑳屾櫙
闂茬殑娌′簨,鑷繁鍐欎簡涓皬缃戠珯,鎼缓鍦ㄨ嚜宸卞浗澶栫殑VPS涓�,VPS鍐呭瓨鏋佸皬(512M),鑰屼笖杩樿璺戠偣鍒殑(浣犳噦鐨�),鍐呭瓨鏇寸揣寮犲反宸�. 鏀归�犱箣鍓嶅皬缃戠珯鐢ㄥ埌浜嗘椂楂︾殑Redis,Rabbmitmq,Mysql,閭f椂鍊欓樋閲屼簯鐨勫鐢熶富鏈哄唴瀛樺瘜瓒�,瑁呰繖涔堝涓棿浠跺帇鍔涗笉澶�,鍙埌浜嗚繖鏍风殑灏忓唴瀛榁PS涓�,涓�鍒囬兘鍙樺緱姘村湡涓嶆湇,绱㈡�у暐涓棿浠堕兘涓嶈浜�,鏁版嵁搴撲篃涓嶈浜�.
娌′簡鏁版嵁搴�,缃戠珯鐨勬暟鎹粠鍝噷鏉�?瀛樺湪鍝噷? 鏂囨湰褰㈠紡鎸佷箙鍖栧埌鏈湴纾佺洏?
鍥藉鐨刅PS涓嶆瘮鍥藉唴,鍙兘鍝ぉ璇翠笉鑳借闂氨涓嶈兘璁块棶浜�,VPS鐨勭鐩樺瓨鍌ㄦ樉鐒朵笉韪忓疄.
鍚屼簨缁欐垜寤鸿浜嗕竾鑳界殑Github,鍚繃Github鎵樼浠g爜馃摐,鎵樼闈欐�侀〉闈煍�,鎵樼濂宠澶т浆馃拑,浣嗘墭绠$綉绔欐暟鎹�掓槸绗竴娆″惉璇�,浜庢槸鎴戝缃戠珯鏋舵瀯杩涜浜嗛噸鏂拌璁�.
Plan1 鏁版嵁鐨勫悓姝�
灏忕綉绔欐暟鎹笉澶�,10M宸﹀彸,鎵�鏈夋暟鎹洿鎺ュ姞杞藉埌鍐呭瓨涓湇鍔″櫒涔熶笉浼氬悆鍔�,缃戠珯鍚姩,鑷姩浠嶨ithub Clone鏁版嵁,骞跺畾鏈熸妸鍐呭瓨涓殑鏁版嵁搴忓垪鍖栧悗Push鍒癎ithub.
鍙互鐪嬪埌,鏁翠釜杩囩▼涓�,濂藉儚娌℃湁纾佺洏鍟ヤ簨浜�,鍦ㄦ垜鐨勭溂閲�,Github灏辨槸涓�鍧楀欢鏃剁暐楂樼殑纾佺洏(鍏跺疄寤舵椂涔熻繕濂�,鍥藉鐨凣ithub璁块棶閫熷害椋炲揩).
Plan2 鍚屾鐨勯鐜�
纾佺洏鐨勮鍙栭�熷害鍜屽唴瀛樻棤娉曟瘮,浣曞喌杩滅▼鐨凣ithub,閭d箞濡傛灉鍑忓皯鏁版嵁浠庡唴瀛樺埌Github鐨勫悓姝ュ紑閿�鍛�?鏄剧劧灏辨槸鍑忓皯鍚屾鐨勯鐜�.
涓�灏忔椂鍚屾涓�娆�,搴旇澶熶簡.
浣嗗鏋滄垜鐨勭綉绔欏湪杩欎竴灏忔椂鎸備簡boom馃寢,鑰屾暟鎹繕娌℃潵寰楀強鍚屾,閭d笂娆′竴鍚屾鍒扮綉绔欐寕鎺夎繖涓椂闂存鍐呯殑鏁版嵁涓嶅氨娌′簡鍚�?缁嗘�濇瀬鎭愷煒�!
Plan3 澶氬涓嶇泭鍠�
鏃㈢劧涓�灏忔椂涓�娆′笉瀹夊叏,閭e氨涓�鍒嗛挓鍚屾涓�娆�!
鍏跺疄杩欐牱涔熸槸鏈夐棶棰樼殑,灏忕綉绔欎竴鑸兘鏄棤浜洪棶娲�,濡傛灉浠ヨ緝楂樼殑棰戠巼杩涜鏁版嵁鍚屾,鍙互璇寸粷澶у鏁�(鐢ㄤ簰鑱旂綉鐨勬墍娉曟槸鐧惧垎涔婲涓�9)鐨勬暟鎹悓姝ラ兘鏄病鎰忎箟鐨�,鍚屾椂杩樺澶т簡鏁版嵁鐨勫悓姝ュ紑閿�,娌″噯Github杩樹細鎶婃垜鐨勮处鍙风粰灏佷簡.
Plan4 鍐呭瓨鏁版嵁鍙樻洿绔嬪嵆瑙﹀彂鏁版嵁鍚屾
鍦ㄦ垜鐨勭綉绔欎腑,鏈夌粺涓�鐨勬暟鎹闂眰,鍙鏁版嵁璁块棶灞備腑鐨刬nsert,update,delete澶勫姞鍏ユ暟鎹悓姝ヤ簨浠�,鍗冲彲瀹炵幇涓�鏃︽洿鏂扮珛鍗冲悓姝�.
杩欐牱鏄暟鎹槸瀹夊叏浜�,鍙槸涓�娆¤闂姹傚線寰�浼撮殢鐫�澶氭鏁版嵁鏇存柊,姣忔洿鏂颁竴娆″悓姝ヤ竴娆�,鍙兘鏄渶鑴戞畫馃檲鐨勫仛娉曞惂.
Question
鏁版嵁鏇存敼涓�娆″悓姝ヤ竴娆′笉鍚堢悊,鍚屾棰戠巼澶綆鏁版嵁涓嶅畨鍏�,棰戠巼澶珮澶氭暟鍚屾娌℃湁鎰忎箟,鍒板簳璇ユ�庢牱鍛�?
灞�閮ㄦ�у師鐞�
鍦ㄦ彮寮�鎴戠殑璁捐鏂规鍓�,鎴戜滑鍏堟潵杩囦竴涓婥PU璁块棶瀛樺偍鍣ㄦ椂鎵�閬靛畧鐨勫眬閮ㄦ�у師鐞�.
鍦ㄨ绠楁満瀛樺偍浠嬭川杩欎釜閲戝瓧濉斾腑,瓒婇潬杩戦噾瀛楀椤剁,绌洪棿瓒婂皬,浣嗘槸璇诲彇鏁版嵁瓒婂揩;瓒婇潬杩戦噾瀛楀搴曠,绌洪棿瓒婂ぇ,浣嗚闂�熷害涔熻秺鎱�.
姝e紡鍥犱负杩欐牱,鎵�浠ユ瘡娆¤嚜涓嬭�屼笂鐨勬暟鎹暟鎹祦澶у皬閫愬眰閫掑, 浜ゆ崲棰戠巼閫愬眰閫掑噺,濡備綍鍦ㄦ椂闂翠笌绌洪棿涓婂彇鍒板钩琛$偣鏄叧閿�.
浜庢槸鏈変簡绌洪棿灞�閮ㄦ�у師鐞嗗拰鏃堕棿灞�閮ㄦ�у師鐞�,鍔涙眰璁╄绠楁満鐨勬暟鎹祦鍔ㄦ洿楂樻晥.
绌洪棿灞�閮ㄦ��
濡傛灉涓�鏉℃暟鎹璁块棶,閭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