![Search icon](https://hackernoon.imgix.net/search-new.png?w=19&h=19)
Ukuqina kusofthiwe kusho ikhono lohlelo lokusebenza ukuqhubeka nokusebenza ngokushelela nangokuthembekile, ngisho nalapho kubhekene nezinkinga ezingalindelekile noma ukwehluleka. Kumaphrojekthi we-Fintech ukuqina kubaluleke kakhulu ngenxa yezizathu ezimbalwa. Okokuqala, izinkampani ziphoqelekile ukuthi zihlangabezane nezidingo zokulawula futhi abalawuli bezezimali bagcizelela ukuqina kokusebenza ukuze kugcinwe uzinzo ngaphakathi kohlelo. Ngaphezu kwalokho, ukwanda kwamathuluzi edijithali nokuthembela kubahlinzeki bezinsizakalo zezinkampani zangaphandle kuveza amabhizinisi akwaFintech ezinsongweni zokuphepha eziphakeme. Ukuqina futhi kusiza ekwehliseni ubungozi bokunqamuka okubangelwa izinto ezahlukahlukene njengokusatshiswa ku-inthanethi, ubhubhane, noma izehlakalo zezwe, ukuvikela ukusebenza kwebhizinisi okuyisisekelo kanye nempahla ebalulekile.
Ngamaphethini okuqina, siqonda isethi yezindlela ezihamba phambili namasu aklanyelwe ukuqinisekisa ukuthi isofthiwe ingakwazi ukumelana nokuphazamiseka futhi igcine ukusebenza kwayo. Lawa maphethini asebenza njengamanethi okuphepha, ahlinzeka ngezindlela zokusingatha amaphutha, ukuphatha umthwalo, kanye nokululama ekuhlulekeni, ngaleyo ndlela kuqinisekiswe ukuthi izinhlelo zokusebenza zihlala ziqinile futhi zithembekile ngaphansi kwezimo ezimbi.
Amasu ajwayelekile okuqina afaka i-bulkhead, inqolobane, i-fallback, zama futhi, kanye ne-circuit breaker. Kulesi sihloko, ngizoxoxa ngazo kabanzi, ngezibonelo zezinkinga ezingasiza ukuzixazulula.
Ake sibheke lesi silungiselelo esingenhla. Sinohlelo lokusebenza olujwayelekile olunama-backend ambalwa ngemuva kwethu ukuze sithole idatha ethile. Kunamaklayenti ambalwa e-HTTP axhunywe kulawa ma-backend. Kuvele ukuthi bonke babelana ngephuli yokuxhumana efanayo! Futhi nezinye izinsiza ezifana ne-CPU ne-RAM.
Kuzokwenzekani, Uma omunye wabangemuva ehlangabezana nohlobo oluthile lwezinkinga eziholela ekubambeni kwesicelo okuphezulu? Ngenxa yesikhathi sokuphendula esiphezulu, yonke indawo yokuxhumana izosetshenziswa ngokugcwele yizicelo ezilinde izimpendulo ezivela ku-backend1. Njengomphumela, izicelo ezihloselwe i-backend2 enempilo kanye ne-backend3 ngeke zikwazi ukuqhubeka ngenxa yokuthi i-pool isiphelile. Lokhu kusho ukuthi ukwehluleka kwesinye sezingemuva zethu kungabangela ukwehluleka kulo lonke uhlelo lokusebenza. Ngokufanelekile, sifuna kuphela ukusebenza okuhlotshaniswa ne-backend ehlulekayo ukuzwa ukucekelwa phansi, kuyilapho lonke uhlelo lokusebenza luqhubeka nokusebenza ngokujwayelekile.
Iyini Iphethini ye-Bulkhead?
Igama elithi, iphethini ye-Bulkhead, lisuselwa ekwakhiweni kwemikhumbi, libandakanya ukwakha amakhompathimenti ambalwa angawodwa ngaphakathi komkhumbi. Uma ukuvuza kwenzeka endaweni eyodwa, igcwala amanzi, kodwa amanye amagumbi ahlala engathinteki. Lokhu kuhlukaniswa kuvimbela umkhumbi wonke ukuthi ungacwili ngenxa yokuphuka okukodwa.
Iphethini ye-Bulkhead ingasetshenziswa ukuhlukanisa izinhlobo ezahlukene zezisetshenziswa ngaphakathi kohlelo lokusebenza, ukuvimbela ukwehluleka engxenyeni eyodwa ukuthikameze isistimu yonke. Nansi indlela esingayisebenzisa ngayo inkinga yethu:
Ake sithi amasistimu ethu angemuva anamathuba amancane okuhlangabezana namaphutha ngawodwana. Kodwa-ke, uma umsebenzi ubandakanya ukubuza zonke lezi zingemuva ngokuhambisana, ngayinye ingabuyisela iphutha ngokuzimele. Ngenxa yokuthi lawa maphutha enzeka ngokuzimela, amathuba ephutha kuhlelo lwethu lokusebenza angaphezulu kwamathuba ephutha anoma iyiphi i-backend eyodwa. Amathuba ephutha akhulayo angabalwa kusetshenziswa ifomula ethi P_total=1−(1−p)^n, lapho u-n eyinombolo yamasistimu angemuva.
Isibonelo, uma sinama-backend ayishumi, ngakunye kunamathuba ephutha okuthi p=0.001 (okuhambisana ne-SLA ka-99.9%), amathuba ephutha angumphumela:
P_ingqikithi=1−(1−0.001)^10=0.009955
Lokhu kusho ukuthi i-SLA yethu ehlanganisiwe yehlela cishe ku-99%, okubonisa ukuthi ukwethembeka kukonke kwehla kanjani lapho kubuzwa ama-backend amaningi ngokuhambisana. Ukuze sinciphise le nkinga, singasebenzisa inqolobane yenkumbulo.
Inqolobane yenkumbulo isebenza njengesilondolozi sedatha esinesivinini esikhulu, igcina idatha efinyelelwa njalo futhi isuse isidingo sokuyilanda emithonjeni enamandla yokunensa njalo. Njengoba izinqolobane ezigcinwe kumemori zinethuba elingu-0% lephutha uma kuqhathaniswa nokulanda idatha ngenethiwekhi, zikhulisa kakhulu ukwethembeka kohlelo lwethu lokusebenza. Ngaphezu kwalokho, ukugcinwa kunqolobane kunciphisa ithrafikhi yenethiwekhi, kwehlisa amathuba amaphutha. Ngokulandelayo, ngokusebenzisa inqolobane yenkumbulo, singakwazi ukuzuza izinga eliphansi lephutha kuhlelo lwethu lokusebenza uma kuqhathaniswa namasistimu ethu angemuva. Ukwengeza, izinqolobane zenkumbulo zinikeza ukubuyiswa kwedatha ngokushesha kunokulanda okusekelwe kunethiwekhi, ngaleyo ndlela kunciphisa ukubambezeleka kohlelo lokusebenza—inzuzo ephawulekayo.
Ngedatha yomuntu siqu, efana namaphrofayela omsebenzisi noma izincomo, ukusebenzisa inqolobane yenkumbulo nakho kungasebenza kakhulu. Kodwa sidinga ukuqinisekisa ukuthi zonke izicelo ezivela kumsebenzisi zihamba ngokungaguquki esihlokweni esifanayo sohlelo lokusebenza ukuze sisebenzise idatha egcinwe kunqolobane yazo, edinga izikhathi ezinamathelayo. Ukusebenzisa izikhathi ezinamathelayo kungaba inselele, kodwa kulesi simo, asidingi izindlela eziyinkimbinkimbi. Ukulinganisa kabusha kwethrafikhi okuncane kuyamukeleka, ngakho-ke i-algorithm ezinzile yokulinganisa umthwalo njenge-hashing engashintshi izokwanela.
Ngaphezu kwalokho, uma kwenzeka iphutha le-node, i-hashing engaguquki iqinisekisa ukuthi abasebenzisi abahlobene ne-node ehlulekile kuphela abathola ukulinganisa kabusha, okunciphisa ukuphazamiseka ohlelweni. Le ndlela yokwenza kube lula ukuphathwa kwama-cache aqondene nawe futhi ithuthukisa ukuzinza kanye nokusebenza kohlelo lwethu lokusebenza.
Uma idatha esihlose ukuyigcina ibalulekile futhi isetshenziswa kuso sonke isicelo esisingathwa yisistimu yethu, njengezinqubomgomo zokufinyelela, izinhlelo zokubhalisa, noma amanye amabhizinisi abalulekile esizindeni sethu—umthombo wale datha ungase ubangele ukwehluleka okukhulu ohlelweni lwethu. Ukuze kubhekwane nale nselele, enye indlela iwukuphindaphinda ngokugcwele le datha ngqo kumemori yohlelo lwethu lokusebenza.
Kulesi simo, uma umthamo wedatha emthonjeni ulawuleka, singaqalisa inqubo ngokulanda isifinyezo sale datha ekuqaleni kohlelo lwethu lokusebenza. Ngokulandelayo, singathola imicimbi yezibuyekezo ukuze siqinisekise ukuthi idatha egcinwe kunqolobane ihlala ivunyelanisiwe nomthombo. Ngokwamukela le ndlela, sithuthukisa ukwethembeka kokufinyelela le datha ebalulekile, njengoba ukubuyisa ngakunye kwenzeka ngokuqondile kumemori ngamaphutha angu-0%. Ukwengeza, ukubuyisa idatha kumemori kuyashesha kakhulu, ngaleyo ndlela kuthuthukisa ukusebenza kohlelo lwethu lokusebenza. Leli su liyinciphisa ngempumelelo ingcuphe ehlobene nokuncika kumthombo wedatha wangaphandle, ukuqinisekisa ukufinyelela okungaguquki nokuthembekile kulwazi olubalulekile ekusebenzeni kohlelo lwethu.
Nokho, isidingo sokudawuniloda idatha ekuqaliseni uhlelo lokusebenza, ngaleyo ndlela kubambezeleka inqubo yokuqalisa, kwephula omunye wemigomo 'yohlelo lokusebenza lwezinto eziyi-12' olumelela ukuqaliswa kwesicelo esisheshayo. Kodwa, asifuni ukulahlekelwa izinzuzo zokusebenzisa ukulondoloza isikhashana. Ukuze sibhekane nale nkinga, ake sihlole izixazululo ezingaba khona.
Ukuqalisa okusheshayo kubalulekile, ikakhulukazi ezisekelweni ezifana ne-Kubernetes, ezithembele ekuthutheleleni kwezinhlelo zokusebenza ngokushesha ziye ezindaweni ezihlukahlukene zomzimba. Ngenhlanhla, i-Kubernetes ingakwazi ukuphatha izinhlelo zokusebenza eziqala kancane isebenzisa izici ezifana nama-probe okuqalisa.
Enye inselele esingase sibhekane nayo ukuvuselela ukucupha ngenkathi uhlelo lokusebenza lusebenza. Ngokuvamile, ukulungisa izikhathi zenqolobane noma ukuvala isikhathi kuyadingeka ukuze kuxazululwe izinkinga zokukhiqiza. Ngisho noma singase sikhiphe ngokushesha amafayela okumisa abuyekeziwe kuhlelo lwethu lokusebenza, ukusebenzisa lezi zinguquko ngokuvamile kudinga ukuqalisa kabusha. Ngesikhathi sokuqalisa esinwetshiwe sohlelo ngalunye, ukuqalisa kabusha kungase kubambezeleke kakhulu ukuthunyelwa kokulungiswa kubasebenzisi bethu.
Ukuze ubhekane nalokhu, isisombululo esisodwa siwukugcina ukulungiselelwa kokuguquguquka okuhambisanayo futhi ube nochungechunge lwangemuva olubuyekezwa njalo. Kodwa-ke, amapharamitha athile, njengokuphelelwa yisikhathi kwesicelo se-HTTP, angase adinge ukuqaliswa kabusha kwe-HTTP noma amaklayenti esizindalwazi lapho ukucushwa okuhambisanayo kushintsha, okudala inselele engaba khona. Nokho, amanye amaklayenti, njengomshayeli we-Cassandra weJava, asekela ukulayisha kabusha okuzenzakalelayo kokucushwa, okwenza le nqubo ibe lula.
Ukusebenzisa ukulungiselelwa okungalayisheka kabusha kunganciphisa umthelela ongemuhle wezikhathi zokuqalisa izinhlelo zokusebenza ezinde futhi kunikeze izinzuzo ezengeziwe, ezifana nokusiza ukusetshenziswa kwefulegi lesici. Le ndlela isenza sikwazi ukugcina ukwethembeka kanye nokusabela kohlelo lokusebenza kuyilapho silawula ngempumelelo izibuyekezo zokucushwa.
Manje ake sibheke enye inkinga: ohlelweni lwethu, lapho isicelo somsebenzisi sitholwa futhi sicutshungulwa ngokuthumela umbuzo ku-backend noma database, ngezikhathi ezithile, impendulo yephutha itholwa esikhundleni sedatha elindelwe. Ngokulandelayo, isistimu yethu iphendula umsebenzisi 'ngephutha'.
Nokho, ezimweni eziningi, kungase kube ngcono kakhulu ukubonisa idatha ephelelwe yisikhathi kancane kanye nomlayezo obonisa ukuthi kukhona ukubambezeleka kokuvuselela idatha, kunokushiya umsebenzisi nomlayezo wephutha omkhulu obomvu.
Ukuze sibhekane nale nkinga futhi sithuthukise indlela yokuziphatha yesistimu yethu, singasebenzisa iphethini ye-Fallback. Umqondo ongemuva kwale phethini ubandakanya ukuba nomthombo wedatha wesibili, ongaqukatha idatha yekhwalithi ephansi noma ubusha obuqhathaniswa nomthombo oyinhloko. Uma umthombo wedatha oyinhloko ungatholakali noma ubuyisela iphutha, isistimu ingabuyela ekubuyiseni idatha esuka kulo mthombo wesibili, iqinisekise ukuthi uhlobo oluthile lolwazi lwethulwa kumsebenzisi esikhundleni sokubonisa umlayezo wephutha.
Uma ubheka isithombe esingenhla, uzobona ukufana phakathi kwenkinga esibhekene nayo manje naleyo esihlangabezane nayo ngesibonelo senqolobane.
Ukuze sikuxazulule, singacabangela ukusebenzisa iphethini eyaziwa ngokuthi zama futhi. Esikhundleni sokuthembela kuma-caches, isistimu ingaklanywa ukuthi ithumele kabusha isicelo ngokuzenzakalelayo uma kwenzeka iphutha. Le phethini uzame futhi inikeza enye indlela elula futhi inganciphisa ngempumelelo amathuba okuba namaphutha kuhlelo lwethu lokusebenza. Ngokungafani nokugcinwa kunqolobane, okuvamise ukudinga izindlela eziyinkimbinkimbi zokungasebenzisi inqolobane yokusingatha izinguquko zedatha, ukuzama futhi izicelo ezihlulekile kulula ukukusebenzisa. Njengoba ukungasebenzi kwenqolobane kuthathwa kabanzi njengomunye wemisebenzi eyinselele kakhulu kubunjiniyela besofthiwe, ukwamukela isu lokuzama kabusha kungenza kube lula ukuphatha amaphutha futhi kuthuthukise ukukhuthazela kwesistimu.
Nokho, ukwamukela isu lokuzama kabusha ngaphandle kokucabangela imiphumela engaba khona kungaholela kwezinye izinkinga.
Ake sicabange omunye wabangemuva kwethu ehlangabezana nokwehluleka. Esimeni esinjalo, ukuqalisa ukuzama kabusha okungemuva okuhlulekayo kungaholela ekwenyukeni okukhulu kwevolumu yethrafikhi. Lokhu kuqubuka kwethrafikhi kungazelelwe kungase kudlule ingemuva, kukhuphule ukwehluleka futhi kubangele umphumela we-cascade kulo lonke uhlelo.
Ukuze ubhekane nale nselele, kubalulekile ukuhambisana nephethini yokuzama futhi ngephethini ye-circuit breaker. I-circuit breaker isebenza njengendlela yokuvikela eqapha izinga lephutha lezinsizakalo ezingezansi. Uma izinga lephutha lidlula umkhawulo oshiwo ngaphambili, i-circuit breaker iphazamisa izicelo zesevisi ethintekile isikhathi esishiwo. Phakathi nalesi sikhathi, isistimu iyagwema ukuthumela izicelo ezengeziwe ukuze ivumele isikhathi sesevisi esihlulekayo ukuthi silulame. Ngemva kwesikhathi esinqunyiwe, i-circuit breaker ivumela ngokuqaphela inani elilinganiselwe lezicelo ukuthi zidlule, iqinisekisa ukuthi isevisi izinzile yini. Uma isevisi isibuyile, ithrafikhi evamile ibuyiselwa kancane kancane; ngaphandle kwalokho, isifunda sihlala sivulekile, siqhubeka nokuvimbela izicelo kuze kube yilapho isevisi iqala kabusha ukusebenza okuvamile. Ngokuhlanganisa iphethini ye-circuit breaker eceleni kokuzama ukucabanga okunengqondo, singaphatha ngempumelelo izimo zamaphutha futhi sigweme ukugcwala kwesistimu phakathi nokuhluleka kwe-backend.
Sengiphetha, ngokusebenzisa la maphethini okuqina, singaqinisa izinhlelo zethu zokusebenza ngokumelene nezimo eziphuthumayo, sigcine ukutholakala okuphezulu, futhi silethe okuhlangenwe nakho okungenazihibe kubasebenzisi. Ukwengeza, ngithanda ukugcizelela ukuthi i-telemetry ingelinye ithuluzi okungafanele lishaywe indiva lapho lihlinzeka ngokuqina kwephrojekthi. Amalogi amahle namamethrikhi angathuthukisa kakhulu ikhwalithi yezinsizakalo futhi anikeze imininingwane ebalulekile ekusebenzeni kwawo, okusiza ukwenza izinqumo ezinolwazi ukuze azithuthukise ngokuqhubekayo.