Home
%3CLINGO-SUB%20id%3D%22lingo-sub-1149025%22%20slang%3D%22en-US%22%3EAutoscaling%20Azure%20SQL%20Hyperscale%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1149025%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fsql-database%2Fsql-database-service-tier-hyperscale%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAzure%20SQL%20Hyperscale%3C%2FA%3E%20is%20the%20latest%20architectural%20evolution%20of%20Azure%20SQL%2C%20that%20has%20been%20natively%20designed%20to%20take%20advantage%20of%20the%20cloud.%20One%20of%20the%20main%20key%20features%20of%20this%20new%20architecture%20is%20the%20complete%20separation%20of%20Compute%20Nodes%20and%20Storage%20Nodes.%20This%20allow%20for%20independent%20scale%20of%20each%20service%2C%20making%20Hyperscale%20more%20flexible%20and%20elastic.%3C%2FP%3E%0A%3CP%3EIn%20this%20article%20I%20will%20describe%20how%20it%20is%20possible%20to%20implement%20a%20solution%20to%20automatically%20scale%20your%20Azure%20SQL%20Hyperscale%20database%20up%20or%20down%2C%20to%20dynamically%20and%20automatically%20adapt%20to%20different%20workload%20levels%20without%20the%20requiring%20manual%20.%3C%2FP%3E%0A%3CP%3ENow%2C%20first%20things%20first.%20I%20won%E2%80%99t%20go%20into%20details%20here%2C%20as%20they%20are%20well%20described%20in%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fsql-database%2Fsql-database-service-tier-hyperscale%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Eofficial%20doc%3C%2FA%3E%2C%20but%20it%20is%20important%20to%20understand%20how%20the%20SQL%20Server%20engine%20has%20been%20refactored%20into%20Azure%20SQL%20Hyperscale%2C%20as%20it%20is%20the%20foundation%20for%20a%20very%20fast%20scale%20up%20and%20down%20of%20the%20selected%20service%20tier.%20Here%E2%80%99s%20a%20picture%20that%20explains%20it%20very%20well%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F168758iE9E6685173D9A3A5%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22clipboard_image_3.png%22%20title%3D%22clipboard_image_3.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOne%20of%20the%20main%20benefit%20of%20this%20architecture%20is%20that%20scaling%20up%20or%20down%20the%20Service%20Level%20Objective%2C%20which%20means%20cores%20and%20ram%2C%20is%20something%20completely%20unrelated%20to%20the%20size%20of%20the%20database.%20Let%E2%80%99s%20say%20for%20examples%20that%20you%20want%20to%20move%20from%20a%20HS_Gen5_2%20to%20HS_Gen5_4.%20This%20is%20on%20overview%20of%20what%20happens%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EA%20new%20Hyperscale%20compute%20node%2C%20with%20the%20new%20requested%20Service%20Level%20Objective%2C%20is%20created%3C%2FLI%3E%0A%3CLI%3ENew%20compute%20finishes%20initialization%20process%20and%20gets%20in%20ready%20state%3C%2FLI%3E%0A%3CLI%3EExisting%20connections%20in%20the%20active%20compute%20node%20are%20terminated%20and%20running%20transactions%20are%20rolled%20back%3C%2FLI%3E%0A%3CLI%3ENew%20connections%20are%20routed%20to%20the%20new%20node%3C%2FLI%3E%0A%3CLI%3EThe%20old%20Hyperscale%20compute%20node%20is%20no%20longer%20used%20for%20this%20database%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EAs%20there%20is%20no%20data%20movement%20involved%2C%20this%20workflow%20happens%20pretty%20quickly.%20In%20several%20tests%20I%20ran%20lately%20I%20had%20a%20pretty%20constant%20value%20of%20maximum%202%20minutes%20to%20spin%20up%20a%20new%20compute%20node%20of%20the%20Service%20Level%20Objective%20you%20are%20asking%20for%2C%20and%20something%20around%2012%20seconds%20to%20actually%20switch%20the%20control%20to%20the%20newly%20created%20node.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F168761iF0C05A2CD4AB764B%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22clipboard_image_6.png%22%20title%3D%22clipboard_image_6.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20all%20the%20time%20required%20to%20spin%20up%20the%20new%20compute%20node%2C%20all%20existing%20connections%20remain%20open%20and%20transactions%20against%20the%20database%20are%20processed%20as%20usual.%20It%E2%80%99s%20only%20during%20the%2012%20seconds%20of%20switch%20that%2C%20at%20some%20point%20during%20that%20time%20range%2C%20connections%20will%20be%20moved%20to%20the%20new%20compute%20node.%20If%20you%20have%20a%20long-running%20transaction%20being%20executed%20at%20the%20time%20of%20cut-off%2C%20it%20will%20be%20rolled%20back%3A%20thanks%20to%20the%20new%26nbsp%3B%20%3CA%20href%3D%22https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dgl193cBJMrw%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAccelerated%20Database%20Recovery%3C%2FA%3E%2C%20this%20operation%20will%20be%20almost%20immediate%20and%20it%20won%E2%80%99t%20prevent%20the%20scaling%20action%20to%20complete.%20Of%20course%20is%20always%20a%20good%20to%20avoid%20to%20re-run%20transactions%2C%20as%20they%20may%20be%20resource-intensive%2C%20so%20follow%20the%20best%20practice%20to%20keep%20the%20connection%20open%20only%20for%20the%20strictly%20needed%20duration%20of%20time.%20If%20you%20are%20used%20to%20work%20with%20HTTP%20and%20REST%2C%20you%20are%20already%20doing%20this%3A%20just%20keep%20doing%20the%20same%20with%20Azure%20SQL%20too.%20If%20you%20are%20using%20some%20tool%20like%20Dapper%2C%20you%20don%E2%80%99t%20even%20have%20to%20bother%20about%20managing%20connections%2C%20unless%20you%20have%20some%20specific%20requirements.%20It%20will%20automatically%20open%20the%20connection%20just%20before%20you%20run%20a%20command%2C%20and%20automatically%20close%20it%20once%20the%20command%20is%20done.%20This%20is%20all%20you%20need%20to%20write%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F168762i9FD3BC9BE6335819%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22clipboard_image_7.png%22%20title%3D%22clipboard_image_7.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1412501200%22%20id%3D%22toc-hId--1412501200%22%20id%3D%22toc-hId--1412501200%22%20id%3D%22toc-hId--1412501200%22%3EMonitoring%20Resource%20Usage%3C%2FH2%3E%0A%3CP%3EAzure%20SQL%20database%20provides%20a%20useful%20DMV%2C%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Frelational-databases%2Fsystem-dynamic-management-views%2Fsys-dm-db-resource-stats-azure-sql-database%3Fview%3Dazuresqldb-current%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Esys.dm_db_resource_stats%3C%2FA%3E%2C%20to%20monitor%20resource%20usage%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F168763i902282D87D564354%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22clipboard_image_8.png%22%20title%3D%22clipboard_image_8.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIt%20retains%20data%20for%20about%201%20hour%2C%20aggregated%20by%2015-seconds%20buckets.%20With%20such%20data%20it%20would%20be%20possible%20to%20do%20some%20really%20fancy%20stuff%20using%20machine%20learning%20and%20some%20cool%20forecasting%20algorithms%2C%20but%20for%20the%20sake%20of%20simplicity%20we%20will%20use%20a%20very%20simple%20moving%20average%20to%20smooth%20out%20peaks%20and%20figure%20out%20if%20we%20need%20to%20scale%20up%20our%20Azure%20SQL%20Hyperscale%20database.%20If%20you%20are%20interested%20in%20better%20algorithms%20to%20determine%20if%20you%20need%20to%20scale%20up%20or%20down%2C%20you%20will%20find%20some%20links%20and%20resources%20at%20the%20end%20of%20this%20post.%3C%2FP%3E%0A%3CP%3EFor%20now%2C%20we%20can%20use%20a%20window%20function%20to%20calculate%20the%20moving%20average%20over%20the%20last%20minute%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F168764i99CC50D4A26A8FAD%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22clipboard_image_9.png%22%20title%3D%22clipboard_image_9.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAside%20from%20the%20moving%20average%2C%20the%20query%20will%20also%20return%20the%20number%20of%20data%20points%20used%20to%20calculate%20the%20average.%20This%20is%20useful%20when%20determine%20if%20scale%20up%20or%20down%20action%20should%20really%20happen.%20If%20fact%2C%20just%20after%20a%20change%20of%20Service%20Level%2C%20say%20from%202vCores%20to%204vCores%2C%20the%20used%20DMV%20will%20be%20completely%20empty.%20So%20for%20one%20minute%20you%20will%20have%20an%20average%20calculated%20on%20way%20less%20data%20that%20what%20you%20want%E2%80%A6and%20this%20could%20lead%20you%20to%20make%20wrong%20assumption%20about%20the%20real%20resource%20usage.%20Due%20to%20application%20reconnecting%20to%20the%20database%2C%20the%20first%20seconds%20could%20be%20even%20without%20load%E2%80%A6and%20you%20should%20not%20take%20any%20action%20(for%20example%20scaling%20down)%20based%20on%20that%20incomplete%20set%20of%20data.%20For%20this%20reason%2C%20the%20sample%20solution%20will%20ignore%20all%20actions%20suggested%20by%20a%20dataset%20that%20doesn%E2%80%99t%20have%20a%20least%20a%20minute%20of%20data.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20want%20to%20calculate%20the%20moving%20average%20over%20a%20longer%20time%20duration%2C%20to%20smooth%20out%20very%20short%20spikes%20of%20workload%20that%20could%20trigger%20unwanted%20scaling%20actions%2C%20you%20can%20just%20increase%20the%20number%20of%20data%20points%2C%20keeping%20in%20mind%20that%20each%20data%20point%20represent%2015%20seconds%20of%20workload.%20This%20is%20the%20code%20you%20want%20to%20look%20at%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F168765iA2F61D868007DD6B%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22clipboard_image_0.png%22%20title%3D%22clipboard_image_0.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAs%20you%20can%20see%2C%20it%20now%20takes%20the%20current%20data%20point%20plus%20the%204%20earlier%20data%20points%20(as%20data%20is%20ordered%20in%20descending%20order%20by%20time).%3C%2FP%3E%0A%3CP%3EIn%20case%20you%20need%20more%20than%20one%20hour%2C%20you%20can%20use%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Frelational-databases%2Fsystem-catalog-views%2Fsys-resource-stats-azure-sql-database%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Esys.resource_stats%3C%2FA%3E%20view%2C%20where%20data%20is%20stored%2C%20with%20a%205-minute%20granularity%2C%20for%2014%20days.%3C%2FP%3E%0A%3CP%3ETake%20a%20look%20at%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Ft-sql%2Fqueries%2Fselect-over-clause-transact-sql%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EOVER%20Clause%20documentation%3C%2FA%3E%20to%20understand%20what%20other%20options%20you%20have%20and%20how%20it%20works.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1075011633%22%20id%3D%22toc-hId-1075011633%22%20id%3D%22toc-hId-1075011633%22%20id%3D%22toc-hId-1075011633%22%3EAutoscaling%20up%20or%20down%3C%2FH2%3E%0A%3CP%3ENow%20that%20we%20have%20a%20simple%20algorithm%20that%20will%20tell%20us%20when%20scale%20up%20is%20needed%20or%20when%20scale%20down%20is%20recommended%2C%20we%20just%20have%20to%20implement%20a%20monitoring%20job%20that%20will%20get%20such%20data%20and%20kick%20off%20the%20scaling%20operation.%3C%2FP%3E%0A%3CP%3EThis%20can%20be%20done%20using%20Azure%20Functions%2C%20as%20they%20support%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-functions%2Ffunctions-bindings-timer%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3ETimer%20Triggers%3C%2FA%3E%2C%20that%20will%20allow%20us%20to%20exactly%20do%20what%20we%20want.%3C%2FP%3E%0A%3CP%3EEvery%2015%20seconds%20the%20Azure%20Function%20will%20wake%20up%2C%20and%20will%20get%20the%20current%20performance%20data%20from%20an%20Azure%20SQL%20Hyperscale%20database%2C%20along%20with%20the%201-minute%20moving%20average.%20If%20the%20moving%20average%20is%20within%20some%20defined%20boundaries%20it%20will%20go%20back%20to%20sleep.%20Otherwise%20a%20scaling%20action%20will%20be%20initiated.%20Here%E2%80%99s%20an%20example%20of%20such%20Azure%20Function%20in%20action%2C%20logging%20into%20%3CFONT%20face%3D%22courier%20new%2Ccourier%22%3Edbo.Autoscaler%3C%2FFONT%3E%20table%20so%20that%20it%20is%20possible%20to%20check%20what%20happened%20and%20why%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F168766i780F1861B945A7C3%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22clipboard_image_1.png%22%20title%3D%22clipboard_image_1.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAs%20visible%20in%20the%20picture%20above%2C%20in%20red%20box%20(box%20%E2%80%9C1%E2%80%9D)%2C%20around%2022%3A12%20GMT%20a%20workload%20spike%20began%2C%20bringing%20Azure%20SQL%20Hyperscale%20CPU%20usage%20close%20to%2080%25.%20After%20a%20minute%20of%20this%20sustained%20workload%2C%20the%20moving%20average%20went%20over%20the%2070%25%20boundary%20and%20thus%20the%20autoscaler%20started%20to%20request%20a%20bump%20in%20the%20Service%20Objective%2C%20asking%20for%20a%20scale%20up%20to%204%20vcores.%3C%2FP%3E%0A%3CP%3EThe%20scale%20up%20happened%20within%2030%20seconds%20and%20then%20autoscaler%20waited%20for%20the%20warmup%20of%20the%20new%20Service%20Objective%20to%20finish%20(the%20NULL%20values%20in%20the%20RequestedSLO%20column)%2C%20as%20during%20warmup%20too%20few%20data%20points%20were%20available%20to%20make%20any%20decision.%20Once%20the%20number%20of%20data%20points%20was%205%20again%2C%20it%20started%20to%20evaluate%20the%20workload%20and%20found%20that%204%20cores%20were%20enough%20to%20handle%20the%20existing%20workload.%20In%20fact%2C%20in%20the%20yellow%20box%20(box%20%E2%80%9C2%E2%80%9D)%2C%20you%20can%20see%20that%20CPU%20usage%20is%20half%20of%20the%20value%20existed%20before%2C%20when%20the%20workload%20spike%20started.%3C%2FP%3E%0A%3CP%3EOne%20thing%20that%20is%20important%20to%20keep%20in%20mind%2C%20is%20that%20every%20time%20that%20scale%20up%20or%20down%20happens%2C%20the%20local%20RPBEX%20cache%20will%20start%20fresh.%20If%20very%20critical%20workload%20this%20can%20have%20an%20impact%20on%20initial%20performances%2C%20as%20data%20needs%20to%20be%20pulled%20from%20page%20servers%20into%20the%20local%20compute%20node%20cache.%20To%20help%20the%20cache%20to%20be%20warm%20as%20fast%20as%20possible%20you%20may%20want%20execute%20some%20specific%20query%20as%20part%20of%20the%20autoscaler%20solution%2C%20just%20to%20make%20sure%20the%20most-used%20data%20is%20in%20the%20local%20cache.%20This%20is%20not%20a%20requirement%20and%20really%20depends%20on%20the%20workload%20you%20have%2C%20but%20is%20some%20cases%20can%20really%20help%20a%20lot%20to%20boost%20the%20performances%20after%20the%20new%20Service%20Level%20Objective%20is%20ready%20to%20be%20used%2C%20so%20keep%20this%20option%20in%20mind%20if%20you%20see%20slower%20than%20expected%20performances%20just%20after%20scale%20up%20or%20down%20happens.%3C%2FP%3E%0A%3CP%3EAt%20a%20later%20point%2C%20around%2022%3A20%20GMT%20the%20workload%20spike%20ends%20and%20in%20a%20minute%20the%20autoscaler%20detects%20that%204%20vCores%20are%20now%20even%20too%20much%20for%20the%20current%20workload%20and%20initiates%20a%20scale-down%20to%202%20cores%20(green%20box%2C%20number%20%E2%80%9C3%E2%80%9D).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--732442830%22%20id%3D%22toc-hId--732442830%22%20id%3D%22toc-hId--732442830%22%20id%3D%22toc-hId--732442830%22%3ESimulating%20workload%3C%2FH2%3E%0A%3CP%3ETo%20simulate%20a%20simple%20workload%20you%20can%20use%20powerful%20load%20testing%20tools%20like%20%3CA%20href%3D%22https%3A%2F%2Flocust.io%2F%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3ELocust%3C%2FA%3E%2C%20%3CA%20href%3D%22https%3A%2F%2Fk6.io%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EK6%26nbsp%3B%3C%2FA%3Eor%20%3CA%20href%3D%22https%3A%2F%2Fjmeter.apache.org%2F%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EApache%20JMeter%3C%2FA%3E%26nbsp%3Bwhere%20you%20can%20simulate%20even%20the%20most%20complex%20and%20realistic%20workload.%20To%20create%20a%20simple%20workload%2C%20a%20nice%20tool%20originally%20written%20by%20Adam%20Machanic%20is%20also%20available%3A%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FErikEJ%2FSqlQueryStress%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3ESQL%20Query%20Stress%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3EAlbeit%20quite%20old%20now%2C%20it%20allows%20you%20to%20execute%20a%20query%20using%20the%20desired%20amount%20of%20parallel%20threads%2C%20so%20that%20you%20can%20create%20some%20workload%20in%20the%20database.%20It%20is%20very%20easy%20to%20use%2C%20configurable%20enough%20and%20is%20great%20to%20quickly%20test%20the%20autoscaling%20sample.%20In%20fact%2C%20a%20.json%20configuration%20file%20is%20also%20included%20in%20autoscaler%E2%80%99s%20GitHub%20repo%2C%20so%20you%20can%20get%20started%20right%20away.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1755070003%22%20id%3D%22toc-hId-1755070003%22%20id%3D%22toc-hId-1755070003%22%20id%3D%22toc-hId-1755070003%22%3ESource%20Code%3C%2FH2%3E%0A%3CP%3ESample%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fyorek%2Fazure-sql-hyperscale-autoscaler%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Esource%20code%20is%20available%20here%3C%2FA%3E.%20If%20you%20want%20to%20contribute%2C%20maybe%20adding%20some%20of%20the%20improvements%20described%20below%2C%20please%20feel%20free%20to%20do%20so.%20I%E2%80%99ll%20be%20more%20than%20happy%20to%20accept%20contributions%20to%20this%20repo.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--52384460%22%20id%3D%22toc-hId--52384460%22%20id%3D%22toc-hId--52384460%22%20id%3D%22toc-hId--52384460%22%3EImprovements%3C%2FH2%3E%0A%3CP%3EUsing%20the%20moving%20average%20to%20figure%20out%20if%20Azure%20SQL%20Hyperscale%20tier%20should%20be%20scaled%20up%20or%20down%20can%20be%20a%20little%20bit%20too%20simplistic%20if%20you%20have%20a%20scenario%20where%20workload%20can%20vary%20with%20very%20complex%20patterns.%20It%20works%20well%20when%20you%20have%20a%20situation%20where%20the%20workload%20spike%20endures%20for%20a%20consistent%20amount%20of%20time%2C%20and%20if%20your%20workload%20fits%20that%20use%20case%2C%20great!%20Just%20keep%20in%20mind%20that%20in%20the%20sample%20we%E2%80%99re%20only%20monitoring%20CPU%20usage%2C%20but%20there%20are%20also%20data%20and%20log%20IO%20usage%20that%20could%20be%20monitored.%20As%20you%20can%20guess%2C%20what%20you%20want%20to%20monitor%2C%20and%20how%20you%20want%20to%20use%20that%20data%20to%20activate%20the%20scale%20up%20or%20down%2C%20is%20really%20up%20to%20you%20and%20very%20specific%20to%20your%20workload%20scenario.%3C%2FP%3E%0A%3CP%3EAs%20mentioned%20already%2C%20this%20is%20just%20a%20sample%2C%20and%20it%20should%20be%20used%20a%20starting%20point%20to%20create%20something%20there%20fits%20your%20own%20use%20case.%20But%20that%E2%80%99s%20the%20only%20improvement%20you%20can%20think%20of.%3C%2FP%3E%0A%3CP%3EIn%20fact%2C%20the%20current%20sample%20just%20reacts%20to%20an%20increased%20or%20decreased%20workload%E2%80%A6which%20means%20that%20it%20will%20starts%20to%20take%20an%20action%20when%20the%20workload%20has%20already%20started%20to%20change.%20If%20the%20workload%20spike%20is%20huge%2C%20the%20allocated%20resources%20may%20not%20be%20able%20to%20satisfy%20it%20within%20the%20desired%20performance%20SLA%20you%20must%20guarantee%2C%20as%20scaling%20will%20happen%20as%20a%20%3CEM%3Econsequence%3C%2FEM%3E%20of%20that%20workload%20change%2C%20and%20sometimes%20even%20causing%20a%20larger%20impact%20due%20to%20the%20necessary%20failover%20during%20the%20spike.%3C%2FP%3E%0A%3CP%3EAnother%20approach%20would%20be%20to%20try%20to%20be%20proactive%20and%20%3CEM%3Epredict%3C%2FEM%3E%20the%20workload%20so%20that%20Azure%20SQL%20Hyperscale%20tier%20could%20be%20changed%20%3CEM%3Ebefore%3C%2FEM%3E%20the%20spike%20happens%2C%20and%20thus%20guaranteeing%20always%20the%20best%20performance%20possible.%3C%2FP%3E%0A%3CP%3EMachine%20learning%20is%20an%20option%20in%20this%20case%2C%20of%20course%2C%20as%20well%20other%20existing%20prediction%20algorithms.%20A%20nice%20blog%20post%20on%20how%20Netflix%20approaches%20to%20this%20problem%20is%20available%20on%20their%20blog%3A%20%3CA%20href%3D%22https%3A%2F%2Fnetflixtechblog.com%2Fscryer-netflixs-predictive-auto-scaling-engine-part-2-bb9c4f9b9385%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EPredictive%20Auto%20Scaling%20Engine%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3EMore%20in%20general%20the%20problems%20fall%20under%20the%20umbrella%20of%20%E2%80%9CDemand%20Forecasting%E2%80%9D%20and%20there%20are%20already%20some%20cool%20algorithms%20in%20Azure%20Machine%20Learning%20services%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fazure.microsoft.com%2Fen-us%2Fblog%2Fbuild-more-accurate-forecasts-with-new-capabilities-in-automated-machine-learning%2F%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAccurate%20Forecast%20with%20Machine%20Learning%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Farchitecture%2Fsolution-ideas%2Farticles%2Fdemand-forecasting%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EDemand%20Forecasting%3C%2FA%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EIf%20you%20want%20even%20more%20options%20this%20blog%20post%20is%20really%20amazing%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftowardsdatascience.com%2Ftime-series-in-python-exponential-smoothing-and-arima-processes-2c67f2a52788%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3ETime%20Series%20in%20Python%2C%20Exponential%20Smoothing%20and%20ARIMA%3C%2FA%3E.%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAzure%20Machine%20learning%20can%20be%20easily%20integrated%20with%20Azure%20Functions%2C%20and%20you%20can%20really%20create%20spectacular%20solution%20using%20Azure%20SQL%20Hyperscale%2C%20Azure%20Machine%20Learning%20and%20Azure%20Functions.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1859838923%22%20id%3D%22toc-hId--1859838923%22%20id%3D%22toc-hId--1859838923%22%20id%3D%22toc-hId--1859838923%22%3EAlternatives%3C%2FH2%3E%0A%3CP%3EThere%20are%20two%20alternatives%20to%20the%20proposed%20sample.%20The%20first%20is%20to%20use%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-monitor%2Fplatform%2Falerts-overview%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAzure%20Alerts%3C%2FA%3E%2C%20where%20you%20can%20do%20pretty%20much%20the%20same%20as%20described%20here%2C%20but%20without%20writing%20code.%20Just%20be%20aware%20that%20the%20telemetry%20log%20available%20to%20Azure%20Alerts%20have%20some%20latency%20%E2%80%93%20usually%20between%202%20and%205%20minutes%20%E2%80%93%20which%20means%20that%20response%20to%20workload%20spike%20will%20be%20not%20as%20fast%20as%20polling%20the%20database%20DMV%20as%20the%20sample%20does.%20If%20you%20don%E2%80%99t%20need%20to%20respond%20to%20workload%20spikes%20in%20less%20than%205%20minutes%2C%20Azure%20Alerts%20can%20be%20a%20great%2C%20simpler%2C%20alternative.%3C%2FP%3E%0A%3CP%3EAnother%20%E2%80%9Csort%20of%E2%80%9D%20alternative%20is%20to%20use%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fsql-database%2Fsql-database-serverless%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAzure%20SQL%20Serverless%3C%2FA%3E%20database%2C%20which%20incorporates%20scale%20up%20and%20down%20natively.%3C%2FP%3E%0A%3CP%3EI%20said%20%E2%80%9Csort%20of%E2%80%9D%20because%20the%20Serverless%20option%20is%20not%20available%20to%20Azure%20SQL%20Hyperscale%20at%20the%20moment%20so%20it%20is%20not%20really%20an%20alternative%2C%20but%20if%20you%20are%20fine%20using%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fsql-database%2Fsql-database-service-tier-general-purpose%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EGeneral%20Purpose%3C%2FA%3E%20service%20tier%2C%20you%E2%80%99ll%20get%20autoscaling%20right%20away%2C%20just%20by%20configuring%20it.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-627673910%22%20id%3D%22toc-hId-627673910%22%20id%3D%22toc-hId-627673910%22%20id%3D%22toc-hId-627673910%22%3EConclusion%3C%2FH2%3E%0A%3CP%3EAutoscaling%20a%20service%20is%20a%20challenging%20job%2C%20especially%20if%20workload%20is%20not%20easy%20predictable.%20But%20thanks%20to%20Azure%20SQL%20Hyperscale%20elasticity%20and%20quick%20scalability%20this%20can%20be%20done%20using%20an%20Azure%20Function%2C%20with%20minimal%20service%20interruption%2C%20especially%20if%20following%20the%20best%20practices%20and%20implementing%20correct%20connection%20retry%20logic.%20Remember%20also%20to%20use%20the%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fdotnet%2FSqlClient%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Elatest%20.NET%20driver%3C%2FA%3E%26nbsp%3Bas%20they%20already%20implement%20some%20reconnection%20logic%20that%20in%20several%20common%20cases%20will%20make%20the%20reconnection%20completely%20transparent.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1149025%22%20slang%3D%22en-US%22%3E%3CP%3EUse%20Azure%20Functions%20to%20automatically%20scale%20up%20and%20down%20Azure%20SQL%20Hyperscale%2C%20taking%20advantage%20of%20its%20cloud-native%20distributed%20services%20architecture%2C%20to%20quickly%20adapt%20to%20different%20workload%20patterns%2C%20efficiently%20managing%20costs%20and%20performance%20requirements%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1149025%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMonitoring%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPerformance%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1151803%22%20slang%3D%22en-US%22%3ERe%3A%20Autoscaling%20Azure%20SQL%20Hyperscale%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1151803%22%20slang%3D%22en-US%22%3E%3CP%3EThank%20you%20Davide%20for%20sharing%20this%20with%20the%20Community%26nbsp%3B%3CIMG%20class%3D%22lia-deferred-image%20lia-image-emoji%22%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Fhtml%2Fimages%2Femoticons%2Fcool_40x40.gif%22%20alt%3D%22%3Acool%3A%22%20title%3D%22%3Acool%3A%22%20%2F%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1152201%22%20slang%3D%22en-US%22%3ERe%3A%20Autoscaling%20Azure%20SQL%20Hyperscale%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1152201%22%20slang%3D%22en-US%22%3E%3CP%3EGreat%20article%2C%20appreciated!%3C%2FP%3E%3C%2FLINGO-BODY%3E
Microsoft

Azure SQL Hyperscale is the latest architectural evolution of Azure SQL, that has been natively designed to take advantage of the cloud. One of the main key features of this new architecture is the complete separation of Compute Nodes and Storage Nodes. This allow for independent scale of each service, making Hyperscale more flexible and elastic.

In this article I will describe how it is possible to implement a solution to automatically scale your Azure SQL Hyperscale database up or down, to dynamically and automatically adapt to different workload levels without the requiring manual .

Now, first things first. I won’t go into details here, as they are well described in the official doc, but it is important to understand how the SQL Server engine has been refactored into Azure SQL Hyperscale, as it is the foundation for a very fast scale up and down of the selected service tier. Here’s a picture that explains it very well:

 

clipboard_image_3.png

 

One of the main benefit of this architecture is that scaling up or down the Service Level Objective, which means cores and ram, is something completely unrelated to the size of the database. Let’s say for examples that you want to move from a HS_Gen5_2 to HS_Gen5_4. This is on overview of what happens:

  • A new Hyperscale compute node, with the new requested Service Level Objective, is created
  • New compute finishes initialization process and gets in ready state
  • Existing connections in the active compute node are terminated and running transactions are rolled back
  • New connections are routed to the new node
  • The old Hyperscale compute node is no longer used for this database

As there is no data movement involved, this workflow happens pretty quickly. In several tests I ran lately I had a pretty constant value of maximum 2 minutes to spin up a new compute node of the Service Level Objective you are asking for, and something around 12 seconds to actually switch the control to the newly created node.

 

clipboard_image_6.png

 

For all the time required to spin up the new compute node, all existing connections remain open and transactions against the database are processed as usual. It’s only during the 12 seconds of switch that, at some point during that time range, connections will be moved to the new compute node. If you have a long-running transaction being executed at the time of cut-off, it will be rolled back: thanks to the new  Accelerated Database Recovery, this operation will be almost immediate and it won’t prevent the scaling action to complete. Of course is always a good to avoid to re-run transactions, as they may be resource-intensive, so follow the best practice to keep the connection open only for the strictly needed duration of time. If you are used to work with HTTP and REST, you are already doing this: just keep doing the same with Azure SQL too. If you are using some tool like Dapper, you don’t even have to bother about managing connections, unless you have some specific requirements. It will automatically open the connection just before you run a command, and automatically close it once the command is done. This is all you need to write:

 

clipboard_image_7.png

 

Monitoring Resource Usage

Azure SQL database provides a useful DMV, sys.dm_db_resource_stats, to monitor resource usage:

 

clipboard_image_8.png

 

It retains data for about 1 hour, aggregated by 15-seconds buckets. With such data it would be possible to do some really fancy stuff using machine learning and some cool forecasting algorithms, but for the sake of simplicity we will use a very simple moving average to smooth out peaks and figure out if we need to scale up our Azure SQL Hyperscale database. If you are interested in better algorithms to determine if you need to scale up or down, you will find some links and resources at the end of this post.

For now, we can use a window function to calculate the moving average over the last minute

 

clipboard_image_9.png

 

Aside from the moving average, the query will also return the number of data points used to calculate the average. This is useful when determine if scale up or down action should really happen. If fact, just after a change of Service Level, say from 2vCores to 4vCores, the used DMV will be completely empty. So for one minute you will have an average calculated on way less data that what you want…and this could lead you to make wrong assumption about the real resource usage. Due to application reconnecting to the database, the first seconds could be even without load…and you should not take any action (for example scaling down) based on that incomplete set of data. For this reason, the sample solution will ignore all actions suggested by a dataset that doesn’t have a least a minute of data.

 

If you want to calculate the moving average over a longer time duration, to smooth out very short spikes of workload that could trigger unwanted scaling actions, you can just increase the number of data points, keeping in mind that each data point represent 15 seconds of workload. This is the code you want to look at:

 

clipboard_image_0.png

 

As you can see, it now takes the current data point plus the 4 earlier data points (as data is ordered in descending order by time).

In case you need more than one hour, you can use the sys.resource_stats view, where data is stored, with a 5-minute granularity, for 14 days.

Take a look at OVER Clause documentation to understand what other options you have and how it works.

 

Autoscaling up or down

Now that we have a simple algorithm that will tell us when scale up is needed or when scale down is recommended, we just have to implement a monitoring job that will get such data and kick off the scaling operation.

This can be done using Azure Functions, as they support Timer Triggers, that will allow us to exactly do what we want.

Every 15 seconds the Azure Function will wake up, and will get the current performance data from an Azure SQL Hyperscale database, along with the 1-minute moving average. If the moving average is within some defined boundaries it will go back to sleep. Otherwise a scaling action will be initiated. Here’s an example of such Azure Function in action, logging into dbo.Autoscaler table so that it is possible to check what happened and why:

 

clipboard_image_1.png

 

As visible in the picture above, in red box (box “1”), around 22:12 GMT a workload spike began, bringing Azure SQL Hyperscale CPU usage close to 80%. After a minute of this sustained workload, the moving average went over the 70% boundary and thus the autoscaler started to request a bump in the Service Objective, asking for a scale up to 4 vcores.

The scale up happened within 30 seconds and then autoscaler waited for the warmup of the new Service Objective to finish (the NULL values in the RequestedSLO column), as during warmup too few data points were available to make any decision. Once the number of data points was 5 again, it started to evaluate the workload and found that 4 cores were enough to handle the existing workload. In fact, in the yellow box (box “2”), you can see that CPU usage is half of the value existed before, when the workload spike started.

One thing that is important to keep in mind, is that every time that scale up or down happens, the local RPBEX cache will start fresh. If very critical workload this can have an impact on initial performances, as data needs to be pulled from page servers into the local compute node cache. To help the cache to be warm as fast as possible you may want execute some specific query as part of the autoscaler solution, just to make sure the most-used data is in the local cache. This is not a requirement and really depends on the workload you have, but is some cases can really help a lot to boost the performances after the new Service Level Objective is ready to be used, so keep this option in mind if you see slower than expected performances just after scale up or down happens.

At a later point, around 22:20 GMT the workload spike ends and in a minute the autoscaler detects that 4 vCores are now even too much for the current workload and initiates a scale-down to 2 cores (green box, number “3”).

 

Simulating workload

To simulate a simple workload you can use powerful load testing tools like Locust, K6 or Apache JMeter where you can simulate even the most complex and realistic workload. To create a simple workload, a nice tool originally written by Adam Machanic is also available: SQL Query Stress.

Albeit quite old now, it allows you to execute a query using the desired amount of parallel threads, so that you can create some workload in the database. It is very easy to use, configurable enough and is great to quickly test the autoscaling sample. In fact, a .json configuration file is also included in autoscaler’s GitHub repo, so you can get started right away.

 

Source Code

Sample source code is available here. If you want to contribute, maybe adding some of the improvements described below, please feel free to do so. I’ll be more than happy to accept contributions to this repo.

 

Improvements

Using the moving average to figure out if Azure SQL Hyperscale tier should be scaled up or down can be a little bit too simplistic if you have a scenario where workload can vary with very complex patterns. It works well when you have a situation where the workload spike endures for a consistent amount of time, and if your workload fits that use case, great! Just keep in mind that in the sample we’re only monitoring CPU usage, but there are also data and log IO usage that could be monitored. As you can guess, what you want to monitor, and how you want to use that data to activate the scale up or down, is really up to you and very specific to your workload scenario.

As mentioned already, this is just a sample, and it should be used a starting point to create something there fits your own use case. But that’s the only improvement you can think of.

In fact, the current sample just reacts to an increased or decreased workload…which means that it will starts to take an action when the workload has already started to change. If the workload spike is huge, the allocated resources may not be able to satisfy it within the desired performance SLA you must guarantee, as scaling will happen as a consequence of that workload change, and sometimes even causing a larger impact due to the necessary failover during the spike.

Another approach would be to try to be proactive and predict the workload so that Azure SQL Hyperscale tier could be changed before the spike happens, and thus guaranteeing always the best performance possible.

Machine learning is an option in this case, of course, as well other existing prediction algorithms. A nice blog post on how Netflix approaches to this problem is available on their blog: Predictive Auto Scaling Engine.

More in general the problems fall under the umbrella of “Demand Forecasting” and there are already some cool algorithms in Azure Machine Learning services:

 

If you want even more options this blog post is really amazing: Time Series in Python, Exponential Smoothing and ARIMA

Azure Machine learning can be easily integrated with Azure Functions, and you can really create spectacular solution using Azure SQL Hyperscale, Azure Machine Learning and Azure Functions.

 

Alternatives

There are two alternatives to the proposed sample. The first is to use Azure Alerts, where you can do pretty much the same as described here, but without writing code. Just be aware that the telemetry log available to Azure Alerts have some latency – usually between 2 and 5 minutes – which means that response to workload spike will be not as fast as polling the database DMV as the sample does. If you don’t need to respond to workload spikes in less than 5 minutes, Azure Alerts can be a great, simpler, alternative.

Another “sort of” alternative is to use Azure SQL Serverless database, which incorporates scale up and down natively.

I said “sort of” because the Serverless option is not available to Azure SQL Hyperscale at the moment so it is not really an alternative, but if you are fine using the General Purpose service tier, you’ll get autoscaling right away, just by configuring it.

 

Conclusion

Autoscaling a service is a challenging job, especially if workload is not easy predictable. But thanks to Azure SQL Hyperscale elasticity and quick scalability this can be done using an Azure Function, with minimal service interruption, especially if following the best practices and implementing correct connection retry logic. Remember also to use the latest .NET driver as they already implement some reconnection logic that in several common cases will make the reconnection completely transparent.

2 Comments

Thank you Davide for sharing this with the Community :cool:

Senior Member

Great article, appreciated!