sql server - Azure SQL frequent connection timeouts -
we're running web app (2 instances) on azure, backed sql azure database. @ given time there 50-150 users using website. database runs @ s2 performance level. dtu around 20% on average.
however, few times every day hundreds of errors in logs timeouts, this:
an error occurred while executing command definition. see inner exception details.
the wait operation timed out.
timeout expired. timeout period elapsed prior completion of operation or server not responding. failure occurred while attempting connect routing destination. duration spent while attempting connect original server - [pre-login] initialization=1; handshake=21; [login] initialization=0; authentication=0; [post-login] complete=1;
we're using ef6 queries default command timeout. i've configured execution strategy:
setexecutionstrategy("system.data.sqlclient", () => new sqlazureexecutionstrategy(10, timespan.fromseconds(15)));
the database (about 15gb total) heavily indexed. these errors occur on place, dozens hundreds within 1-2 minutes.
what steps can take prevent happening?
the fact happens in 1-2 minutes might mean burst in activity or process might locking tables.
if dtu during times @ 20% not cpu issue, can find bottlenecks running query on db:
select top 10 total_worker_time/execution_count avg_cpu_time ,execution_count ,total_elapsed_time/execution_count avg_run_time ,(select substring(text,statement_start_offset/2,(case when statement_end_offset = -1 len(convert(nvarchar(max), text)) * 2 else statement_end_offset end -statement_start_offset)/2 ) sys.dm_exec_sql_text(sql_handle) ) query_text sys.dm_exec_query_stats order avg_cpu_time desc
even if db heavily indexed, indexes fragmented, i'd advice running check current fragmentation:
select a.*,b.averagefragmentation ( select tbl.name [table_name], tbl.object_id, i.name [name], i.index_id, cast(case i.index_id when 1 1 else 0 end bit) [isclustered], cast(case when i.type=3 1 else 0 end bit) [isxmlindex], cast(case when i.type=4 1 else 0 end bit) [isspatialindex] sys.tables tbl inner join sys.indexes on (i.index_id > 0 , i.is_hypothetical = 0) , (i.object_id=tbl.object_id))a inner join ( select tbl.object_id, i.index_id, fi.avg_fragmentation_in_percent [averagefragmentation] sys.tables tbl inner join sys.indexes on (i.index_id > 0 , i.is_hypothetical = 0) , (i.object_id=tbl.object_id) inner join sys.dm_db_index_physical_stats(db_id(), null, null, null, 'limited') fi on fi.object_id=cast(i.object_id int) , fi.index_id=cast(i.index_id int) )b on a.object_id=b.object_id , a.index_id=b.index_id order averagefragmentation desc
you can use azure automation schedule automatic rebuilding of fragmented indexes, see answer at: why azure sql database indexes still fragmented?
Comments
Post a Comment