![Search icon](https://hackernoon.imgix.net/search-new.png?w=19&h=19)
Ukomelela kwisoftware kubhekisa ekukwazini kwesicelo ukuqhubeka nokusebenza kakuhle nangokuthembekileyo, naxa kukho imiba engalindelekanga okanye ukusilela. Kwiiprojekthi zeFintech ukomelela kubaluleke kakhulu ngenxa yezizathu ezininzi. Okokuqala, iinkampani zibophelelekile ukuba zihlangabezane neemfuno zolawulo kwaye abalawuli bezemali bagxininisa ukomelela ekusebenzeni ukugcina uzinzo ngaphakathi kwenkqubo. Ngaphezu koko, ukwanda kwezixhobo zedijithali kunye nokuthembela kubaboneleli beenkonzo zomntu wesithathu kuveza amashishini eFintech kwizoyikiso zokhuseleko ezongeziweyo. Ukomelela kwakhona kunceda ukunciphisa umngcipheko wokungabikho okubangelwa zizinto ezahlukeneyo ezinje ngezoyikiso ze-cyber, ubhubhane, okanye iminyhadala ye-geopolitical, ukukhusela imisebenzi engundoqo yeshishini kunye nempahla ebalulekileyo.
Ngeepateni zokomelela, siqonda isethi yeendlela ezilungileyo kunye nezicwangciso eziyilelwe ukuqinisekisa ukuba isoftware inokumelana nokuphazamiseka kwaye igcine imisebenzi yayo. Ezi patheni zisebenza njengeminatha yokhuseleko, ibonelela ngeendlela zokusingatha iimpazamo, ukulawula umthwalo, kunye nokubuyisela ekuphumeleleni, ngaloo ndlela iqinisekisa ukuba izicelo zihlala zomelele kwaye zixhomekeke phantsi kweemeko ezimbi.
Ezona zicwangciso zixhaphakileyo zokomelela zibandakanya i-bulkhead, i-cache, i-fallback, ukuzama kwakhona, kunye ne-circuit breaker. Kweli nqaku, ndiza kuxoxa ngazo ngokubanzi, kunye nemizekelo yeengxaki ezinokunceda ukuzisombulula.
Makhe siqwalasele le setingi ingasentla. Sinesicelo esiqhelekileyo esinee-backends ezininzi emva kwethu ukuze sifumane idatha evela. Kukho abaxhasi abaninzi beHTTP abaqhagamshelwe kwezi mva. Kuyavela ukuba bonke babelana ngedama lonxibelelwano olufanayo! Kwaye nezinye izixhobo ezifana ne-CPU kunye ne-RAM.
Kuya kwenzeka ntoni, ukuba omnye wababuyela ngasemva ufumana uhlobo lweengxaki ezikhokelela kwisicelo esiphezulu sokubambezeleka? Ngenxa yexesha eliphezulu lokuphendula, yonke indawo yokudibanisa iya kuhlala ngokupheleleyo ngezicelo ezilindele iimpendulo ezivela kwi-backend1. Ngenxa yoko, izicelo ezijoliswe kwi-backend2 enempilo kunye ne-backend3 aziyi kukwazi ukuqhubeka ngenxa yokuba i-pool iphelile. Oku kuthetha ukuba ukusilela kwenye yee-backends zethu kunokubangela ukusilela kulo lonke usetyenziso. Ngokufanelekileyo, sifuna kuphela usebenziso oluyanyaniswa ne-backend engaphumeleliyo ukufumana ukuthotywa, ngelixa sonke isicelo siqhubeka nokusebenza ngokwesiqhelo.
Yintoni iPatheni yeBulkhead?
Igama elithi, ipateni yeBulkhead, lisuka kulwakhiwo lweenqanawa, libandakanya ukwenza amacandelo ahlukeneyo abucala ngaphakathi kwenqanawa. Ukuba ukuvuza kwenzeka kwelinye igumbi, lizalisa ngamanzi, kodwa amanye amacandelo ahlala engachaphazeleki. Oku kwahlula kuthintela inqanawa yonke ekuzikeni ngenxa yokwaphuka okukodwa.
Ipatheni yeBulkhead ingasetyenziselwa ukwahlula iindidi ezahlukeneyo zezibonelelo ngaphakathi kwesicelo, ukuthintela ukungaphumeleli kwinxalenye enye ekuchaphazeleni inkqubo yonke. Nantsi indlela esinokuyisebenzisa ngayo kwingxaki yethu:
Masithi iisistim zethu zasemva zinethuba eliphantsi lokudibana neempazamo nganye. Nangona kunjalo, xa usebenziso lubandakanya ukubuza zonke ezi zinto zingasemva ngokunxuseneyo, nganye inokubuyisela impazamo ngokuzimeleyo. Ngenxa yokuba ezi mpazamo zisenzeka ngokuzimeleyo, amathuba eempazamo kwisicelo sethu angaphezulu kwempazamo yaso nasiphi na isiphene esinye. Imposiso eyongezelekayo inokubalwa kusetyenziswa ifomula P_total=1−(1−p)^n, apho u-n linani leenkqubo zomva.
Umzekelo, ukuba sinama-backend alishumi, nganye inemposiso enokwenzeka ye-p=0.001 (ehambelana ne-SLA ka-99.9%), imposiso enokwenzeka enokwenzeka yile:
P_itotali=1−(1−0.001)^10=0.009955
Oku kuthetha ukuba i-SLA yethu edibeneyo yehla ukuya malunga ne-99%, ebonisa ukuba ukuthembeka kukonke kuncipha njani xa ubuza ii-backends ezininzi ngaxeshanye. Ukunciphisa lo mba, sinokusebenzisa i-cache ekwimemori.
I-cache ekwimemori isebenza njengesithinteli sedatha esinesantya esiphezulu, igcina idatha efikelelwa rhoqo kwaye isusa imfuneko yokuyilanda kwimithombo enokucotha ngalo lonke ixesha. Ekubeni ii-cache ezigcinwe kwi-memory zine-0% ithuba lempazamo xa kuthelekiswa nokulanda idatha kwinethiwekhi, zonyusa kakhulu ukuthembeka kwesicelo sethu. Ngaphezu koko, i-caching inciphisa itrafikhi yenethiwekhi, inciphisa ngakumbi ithuba leempazamo. Ngenxa yoko, ngokusebenzisa i-cache yememori, sinokufikelela nakwinqanaba lempazamo elisezantsi kwisicelo sethu xa kuthelekiswa neenkqubo zethu zangasemva. Ukongezelela, ii-cache ze-memory zinika ukubuyiswa kwedatha ngokukhawuleza kunokulanda okusekwe kwinethiwekhi, ngaloo ndlela kuncitshiswe i-latency yesicelo-inzuzo ephawulekayo.
Kwidatha eyenzelwe wena, efana neeprofayili zabasebenzisi okanye iingcebiso, ukusebenzisa i-cache yememori kunokusebenza kakhulu. Kodwa kufuneka siqinisekise ukuba zonke izicelo ezisuka kumsebenzisi zisoloko zisiya kumzekelo wesicelo ofanayo ukuze sisebenzise idatha egcinwe kuyo, nto leyo efuna iiseshini ezincangathi. Ukuphumeza iiseshini ezincangathi kunokuba ngumngeni, kodwa kule meko, asidingi zixhobo zintsonkothileyo. Ukulungelelaniswa kwakhona kwetrafikhi encinci kwamkelekile, ngoko ke i-algorithm ezinzileyo yokulinganisa umthwalo njenge-hashing engaguqukiyo iya kwanela.
Ngaphezu koko, xa kukho ukungaphumeleli kwe-node, i-hashing engaguqukiyo iqinisekisa ukuba kuphela abasebenzisi abanxulumene ne-node engaphumeleliyo baphinde balungelelanise, ukunciphisa ukuphazamiseka kwinkqubo. Le ndlela yokwenza lula ulawulo lwee-cache ezenzelwe wena kwaye yongeza uzinzo kunye nokusebenza kosetyenziso lwethu.
Ukuba idatha esizimisele ukuyigcina ibalulekile kwaye isetyenziswa kwisicelo ngasinye esiphathwa yinkqubo yethu, njengemigaqo-nkqubo yofikelelo, izicwangciso zobhaliso, okanye amanye amaziko abalulekileyo kwindawo yethu—umthombo wale datha unokubangela ukusilela kwinkqubo yethu. Ukujongana nalo mngeni, enye indlela kukuphinda-phinda ngokupheleleyo le datha kwinkumbulo yesicelo sethu.
Kule meko, ukuba umthamo wedatha kumthombo uyalawuleka, sinokuqalisa inkqubo ngokukhuphela i-snapshot yale datha ekuqaleni kwesicelo sethu. Emva koko, sinokufumana uhlaziyo lweziganeko zokuqinisekisa ukuba idatha egciniweyo ihlala ilungelelaniswa nomthombo. Ngokwamkela le ndlela, sikhulisa ukuthembeka kokufikelela kule datha ibalulekileyo, njengoko ukufunyanwa ngalunye kwenzeka ngokuthe ngqo kwimemori nge-0% yempazamo enokwenzeka. Ukongeza, ukubuyisela idatha kwimemori kukhawuleza kakhulu, ngaloo ndlela kunyuswa ukusebenza kwesicelo sethu. Esi sicwangciso-qhinga sithomalalisa umngcipheko onxulumene nokuxhomekeka kumthombo wedatha wangaphandle, ukuqinisekisa ukufikelela okungaguqukiyo nokuthembekileyo kulwazi olubalulekileyo ekusebenzeni kwesicelo sethu.
Nangona kunjalo, imfuno yokukhuphela idatha ekuqalisweni kwesicelo, ngaloo ndlela ilibazisa inkqubo yokuqalisa, iphula enye yemigaqo 'yesicelo se-12-factor' ekhuthaza ukuqaliswa ngokukhawuleza kwesicelo. Kodwa, asifuni kuphulukana nezibonelelo zokusebenzisa i-caching. Ukuhlangabezana nale ngxaki, makhe sijonge izisombululo ezinokubakho.
Ukuqalisa ngokukhawuleza kubalulekile, ngakumbi kumaqonga afana ne-Kubernetes, axhomekeke kwisicelo esikhawulezayo sokufudukela kwiindawo ezahlukeneyo zomzimba. Ngethamsanqa, i-Kubernetes inokulawula usetyenziso oluqala kancinci isebenzisa iimpawu ezinje ngeeprobe zokuqalisa.
Omnye umngeni esinokujongana nawo kukuhlaziya ulungelelwaniso ngelixa usetyenziso lusaqhuba. Rhoqo, ukulungelelanisa amaxesha e-cache okanye ukucela ukuphelelwa lixesha kuyafuneka ukusombulula imiba yemveliso. Nokuba sinokuthumela ngokukhawuleza iifayile zoqwalaselo ezihlaziyiweyo kwisicelo sethu, ukusebenzisa olu tshintsho kufuna ukuqaliswa kwakhona. Ngexesha elongeziweyo lokuqalisa kwesicelo ngasinye, ukuqalisa ngokutsha kunokulibazisa kakhulu ukusasaza izilungiso kubasebenzisi bethu.
Ukujongana noku, isisombululo esinye kukugcina uqwalaselo kuguqulo oluhambelanayo kwaye ube nomsonto ongasemva uwuhlaziya rhoqo. Nangona kunjalo, iiparamitha ezithile, ezifana nokuphuma kwexesha lesicelo se-HTTP, kunokufuna ukuqaliswa kwakhona kwe-HTTP okanye abathengi bedatabase xa ulungelelwaniso oluhambelanayo lutshintsha, lubeka umngeni onokubakho. Nangona kunjalo, abanye abathengi, njengomqhubi weCassandra weJava, baxhasa ukulayishwa kwakhona ngokuzenzekelayo koqwalaselo, ukwenza lula le nkqubo.
Ukuphumeza ulungelelwaniso oluphinda lulayisheke kunokunciphisa ifuthe elibi lamaxesha amade okuqalisa kwesicelo kwaye kubonelele ngezibonelelo ezongezelelweyo, ezifana nokuququzelela ukuphunyezwa kweflegi. Le ndlela isenza sikwazi ukugcina ukuthembeka kwesicelo kunye nokuphendula ngelixa silawula ngokufanelekileyo ukuhlaziywa kobumbeko.
Ngoku makhe sijonge enye ingxaki: kwinkqubo yethu, xa isicelo somsebenzisi sifunyenwe kwaye siqhutywe ngokuthumela umbuzo kwi-backend okanye i-database, ngamanye amaxesha, impendulo yephutha ifunyenwe endaweni yedatha elindelekileyo. Emva koko, inkqubo yethu iphendula kumsebenzisi 'ngempazamo'.
Nangona kunjalo, kwiimeko ezininzi, kunokukhethwa ngakumbi ukubonisa idatha ephelelwe lixesha kunye nomyalezo obonisa ukuba kukho ukulibaziseka kokuhlaziywa kwedatha, kunokushiya umsebenzisi nomyalezo omkhulu wephutha obomvu.
Ukulungisa lo mba kunye nokuphucula indlela yokuziphatha kwesixokelelwano sethu, singasebenzisa ipateni yokubuyela umva. Ingcinga esemva kwale pateni ibandakanya ukuba nomthombo wedatha wesibini, onokuqulatha idatha yomgangatho ophantsi okanye ubutsha xa kuthelekiswa nomthombo wokuqala. Ukuba umthombo wedatha osisiseko awufumaneki okanye ubuyisela impazamo, inkqubo inokubuyela umva ekufumaneni idatha evela kulo mthombo wesibini, iqinisekisa ukuba uhlobo oluthile lolwazi lunikezelwe kumsebenzisi endaweni yokubonisa umyalezo wemposiso.
Ukuba ujonga lo mfanekiso ungasentla, uya kuqaphela ukufana phakathi komba esijongene nawo ngoku kunye nalowo sidibene nomzekelo we-cache.
Ukuyicombulula, sinokuqwalasela ukuphumeza ipateni eyaziwa ngokuba yizama kwakhona. Esikhundleni sokuxhomekeka kwii-cache, inkqubo inokuthi yenziwe ukuba ithumele ngokuzenzekelayo isicelo xa kukho impazamo. Le pateni uzame kwakhona inika enye indlela elula kwaye inokunciphisa ngokusebenzayo ukubakho kweempazamo kwisicelo sethu. Ngokungafaniyo ne-caching, ehlala ifuna iindlela ezintsonkothileyo zokunganyaniseki kwe-cache yokusingatha utshintsho lwedatha, ukuzama kwakhona izicelo ezisileleyo kulula kakhulu ukuphumeza. Njengoko ukungasebenzi kwe-cache kuthathwa ngokubanzi njengowona msebenzi ucela umngeni kubunjineli besoftware, ukwamkela isicwangciso sokuphinda sizame kunokulungelelanisa ukuphatha iimpazamo nokuphucula ukomelela kwenkqubo.
Nangona kunjalo, ukwamkela isicwangciso-qhinga sokuphinda uzame ngaphandle kokuqwalasela iziphumo ezinokubakho kunokukhokelela kwezinye iingxaki.
Makhe sicinge ukuba omnye wabasemva bethu ufumana ukusilela. Kwimeko enjalo, ukuqalisa ukuzama kwakhona kwi-backend engaphumeleliyo kunokukhokelela ekunyuseni okukhulu komthamo wezithuthi. Oku kunyuka ngesiquphe kwetrafikhi kunokongamela umva, kwenze mandundu ukusilela kwaye kunokubangela isiphumo se-cascade kuyo yonke inkqubo.
Ukuhlangabezana nalo mngeni, kubalulekile ukuzalisekisa ipateni yokuphinda uzame kunye nepateni ye-circuit breaker. I-breaker circuit isebenza njengendlela yokukhusela ebeka esweni izinga lempazamo kwiinkonzo ezisezantsi. Xa izinga lephutha lidlula umda ochazwe ngaphambili, i-breaker circuit iphazamisa izicelo kwinkonzo echaphazelekayo kwixesha elichaziweyo. Ngeli xesha, inkqubo iyayeka ukuthumela izicelo ezongezelelweyo ukuvumela ixesha lenkonzo engaphumeleli ukuba libuyiselwe. Emva kwexesha elimiselweyo, i-circuit breaker ivumela ngokukhawuleza inani elincinci lezicelo ukuba lidlule, liqinisekisa ukuba inkonzo izinzile. Ukuba inkonzo ibuyiselwe, i-traffic eqhelekileyo ibuyiselwa ngokuthe ngcembe; ngaphandle koko, isekethe ihlala ivulekile, iqhubeka ivimbela izicelo de inkonzo iphinde iqalise ukusebenza okuqhelekileyo. Ngokudibanisa ipateni ye-breaker circuit ecaleni kwe-logic yokuzama kwakhona, sinokulawula ngokufanelekileyo iimeko zempazamo kwaye sithintele ukugqithiswa kwenkqubo ngexesha lokungaphumeleli kwe-backend.
Ukuqukumbela, ngokuphumeza ezi patheni zokomelela, sinokomeleza izicelo zethu ngokuchasene neemeko ezingxamisekileyo, sigcine ukufumaneka okuphezulu, nokuhambisa amava angenamthungo kubasebenzisi. Ukongeza, ndingathanda ukugxininisa ukuba i-telemetry sesinye isixhobo esingafanelanga singahoywa xa sibonelela ngeprojekthi ukomelela. Iilogi ezilungileyo kunye neemetrics zinokuphucula kakhulu umgangatho weenkonzo kwaye zibonelele ngengqiqo ebalulekileyo ekusebenzeni kwazo, ukunceda ukwenza izigqibo ezinolwazi ukuziphucula ngakumbi.