Imwe yemibvunzo yandinofarira yekubvunzurudza ndeye "Mazwi akadai seasync uye akamirira anokuudza chii?" nekuti zvinovhura mukana wekuita nhaurirano inofadza neanobvunzurudzwa… Kana kuti hazvidaro nekuti vanoyangarara pamusoro pechinyorwa ichi. Mune maonero angu, zvakakosha zvikuru kunzwisisa kuti nei tichishandisa nzira iyi.
Ini ndinonzwa sekunge vazhinji vanogadzira vanosarudza kuvimba ne "ndiyo yakanakisa tsika" chirevo uye kushandisa asynchronous nzira nehupofu.
Ichi chinyorwa chinoratidza musiyano pakati peasynchronous uye synchronous nzira mukuita.
Ini ndichamhanyisa bhenji nenzira inotevera. Mhashu mbiri dzakazvimirira dziri kushanda pamichina miviri. Mhashu zviitiko zvinotevedzera mushandisi anoita zvinotevera:
Pasi pehodhi, imwe neimwe App Service inobatanidza kune yayo yega dhatabhesi uye inoita SELECT query inotora masekonzi mashanu uye inodzosa mitsetse mishoma yedata. Ona kodhi yemutongi pazasi kuti uwane mareferensi. Ini ndichashandisa Dapper kufona kune database. Ndinoda kukwevera pfungwa dzako kune chokwadi chekuti iyo asynchronous endpoint inodaidza dhatabhesi asynchronously zvakare ( QueryAsync<T> ).
Zvakakodzera kuwedzera kuti ini ndinotumira iyo kodhi yakafanana kune ese ari maviri app masevhisi.
Munguva yekuedzwa, nhamba yevashandisi inokura zvakaenzana kusvika kunhamba inotarirwa ( Nhamba yeVashandisi ). Iko kumhanya kwekukura kunodzorwa neSpawn Rate parameter (nhamba yevashandisi vakasiyana kujoina pasekondi) - iyo yakakwira iyo nhamba, inokurumidza vashandisi vari kuwedzerwa. The spawn rate inotarwa kune gumi vashandisi/s kune zvese zviedzo.
Kuedza kwese kunogumira kumaminitsi gumi nemashanu.
Unogona kuwana ruzivo rwemuchina muchikamu cheTechnical Details chechinyorwa.
Mitsetse mitsvuku inoreva asynchronous, uye mitsara yebhuruu - kune iyo synchronous endpoint, zvichiteerana.
Ndizvo zviri pamusoro pedzidziso. Ngatitange.
Isu tinogona kuona kuti ese ari maviri ekupedzisira anoita zvakafanana - kubata akatenderedza 750 zvikumbiro paminiti ine yepakati mhinduro nguva ye5200 ms.
Iyo inonyanya kunakidza girafu muchiyedzo ichi ndeye thread maitiro. Iwe unogona kuona yakakwira nhamba dzeiyo synchronous endpoint (girafu rebhuruu) - anopfuura zana shinda!
Izvo zvinotarisirwa, zvakadaro, uye zvinoenderana nedzidziso - kana chikumbiro chapinda, uye chikumbiro chikaita runhare kune dhatabhesi, tambo yakavharwa nekuti inofanirwa kumirira kutenderera kupedzisa. Naizvozvo, kana chimwe chikumbiro chapinda, chikumbiro chinofanira kuburitsa shinda nyowani yekuchibata.
Girafu dzvuku - iyo asynchronous endpoint thread count- inoratidza maitiro akasiyana. Kana chikumbiro chikauya uye chikumbiro chikaita kufona kune dhatabhesi, iyo tambo inodzokera kune tambo dziva pane kuvharwa. Naizvozvo, kana chimwe chikumbiro chapinda, iyi tambo yemahara inoshandiswa zvakare. Kunyangwe zvikumbiro zvinouya zvichikura, chishandiso hachidi chero tambo nyowani, saka kuverenga kwavo kunoramba kwakafanana.
Zvakakodzera kutaura iyo 3rd metric — median mhinduro nguva . Mapeji ese ari maviri airatidza mhedzisiro yakafanana - 5200 ms. Saka, hapana musiyano maererano nekuita.
Zvino, yave nguva yekudhonza matanda.
Takawedzera mutoro. Mugumo usingaenzaniswi unobata basa iri zvinobudirira— chikumbiro chayo paminiti imwe neimwe chinoyangarara chakapoteredza 1500. Hama inowirirana yakazosvika nhamba inoenzana ne1410. Asi kana ukatarisa girafu riri pasi apa, uchaona kuti zvakatora maminitsi gumi!
Chikonzero ndechekuti iyo synchronous endpoint inopindirana nekusvika kwemushandisi mutsva nekugadzira imwe tambo, asi vashandisi vari kuwedzerwa kune sisitimu (kungokuyeuchidzai kuti Spawn Rate ndeye gumi vashandisi / s) nekukurumidza kupfuura iyo webhu server inogona kuchinjika. Ndosaka yakaronga zvikumbiro zvakawanda pakutanga.
Zvisingashamise, iyo tambo yekuverenga metric ichiri kutenderera makumi matatu nemana kune iyo asynchronous endpoint, nepo yakawedzera kubva pa102 kuenda ku155 kune inowirirana. Nguva yekupindura yepakati yakaderedzwa zvakafanana nekukumbira paminiti mwero - iyo synchronous yekupindura nguva yaive yakakwira zvakanyanya pakutanga kwekuyedza. Dai ndakachengeta bvunzo kwemaawa makumi maviri nemana, nhamba dzepakati dzaizoenzana.
Kuedza kwechitatu kunoitirwa kuratidza mafambiro akaratidzwa panguva yechipiri-tinogona kuona kumwe kuderedzwa kweiyo synchronous endpoint.
Kushandisa asynchronous pachinzvimbo che synchronous mashandiro haagadzirise zvakananga kuita kana ruzivo rwemushandisi. Kutanga, inowedzera kugadzikana uye kufanotaura pasi pekumanikidzwa. Mune mamwe mazwi, inosimudza chikumbaridzo chemutoro kuitira kuti sisitimu igadzirise zvakanyanya isati yadzikisira.
Kuti ndiwane yakachena bvunzo mhedzisiro, ndinofanira kunge ndakamhanyisa bvunzo kubva ku2 VMs iri mune imwecheteyo network panogara iyo inotarirwa App Services.
Nekudaro, ini ndakafungidzira kuti network lag yaizokanganisa ese maapplication nenzira yakawedzera kana kushoma yakafanana. Naizvozvo, haigone kukanganisa chinangwa chikuru - kuenzanisa maitiro asynchronous uye synchronous maitiro.
Chii chandakabira kumanikidza iyo inopindirana magumo kuti iite senge asynchronous uye kuronga girafu pazasi (mamiriro ekuyedza akafanana neyechitatu - vashandisi mazana maviri)?