Merhaba,
İndeks oluşturmak performans artırma konusunda size yardımcı olabilir. Ayrıca, SSMS ve uygulamada çalışan sorgurda farklılılar olup olmadığına bir bakabilirsiniz.
Bu tarayıcı artık desteklenmiyor.
En son özelliklerden, güvenlik güncelleştirmelerinden ve teknik destekten faydalanmak için Microsoft Edge’e yükseltin.
.Net 8.0 ortamında geliştirilen bir web api uygulamam var. Client tarafından API başvurusuna yanıt çok geç dönmekte. İlgili controller içerisindeki sorguyu oluşturan context yapısı aşağıdaki gibi;
`var devices = await _contextMivo.Devices`
```` .Where(x => x.Customerschema == _apiUser.Customerschema)`
` .ToListAsync();`
` var deviceIds = devices.Select(d => d.Deviceid).ToList();`
` var wakeUpDatas = await _contextMivo.Wakeups`
` .Where(x =>`
` x.Customerschema == _apiUser.Customerschema &&`
` deviceIds.Contains(x.Deviceid) &&`
` x.Dateandtime >= input.StartDate &&`
` x.Dateandtime <= input.StopDate`
` )`
` .OrderByDescending(x => x.Dateandtime)`
` .ToListAsync();`
Buradaki işlem sonrasında Visual Studio > Output penceresinde çıkan T-SQL sorgusunu SSMS üzerinden çalıştırdığımda 1 saniye kadar sürede veriler listeleniyor. Fakat bu süre uygulama üzerinden başvurularda 80 saniyelere kadar çıkıyor.
Veri tabanı tablosunda herhangi bir indeksleme vs yok. Ayrıca local makina üzerinde çalışıyorum.
Nedeninin ne olacağı ile ilgili bir fikriniz var mıdır?
Merhaba,
İndeks oluşturmak performans artırma konusunda size yardımcı olabilir. Ayrıca, SSMS ve uygulamada çalışan sorgurda farklılılar olup olmadığına bir bakabilirsiniz.
var devices = await _contextMivo.Devices.toList()
şeklinde sorguları değiştirip denermisiniz
this smells like the Contains(deviceIds) round-trip + tracking + big materialization, not the db itself. SSMS is fast cuz you probably ran a simplified sql with ids inlined; EF sends a fat IN (@p0,@p1,...) with lots of params, tracks every row, then sorts + serializes. that combo can easily hit 10–80s on app side even when sql is ~1s.
do it in one server-side query, no tracking, no intermediate list. something like:
var wakeUps = await _contextMivo.Wakeups
.AsNoTracking()
.Where(w => w.Customerschema == _apiUser.Customerschema
&& w.Dateandtime >= input.StartDate
&& w.Dateandtime <= input.StopDate)
.Join(
_contextMivo.Devices
.AsNoTracking()
.Where(d => d.Customerschema == _apiUser.Customerschema),
w => w.Deviceid,
d => d.Deviceid,
(w, d) => w
)
.OrderByDescending(w => w.Dateandtime)
.ToListAsync();
if you don’t need all cols, project early to a dto (less json). also make sure the action isn’t returning megabytes uncompressed. if it’s still slow, there’s likely no index on (Customerschema, Deviceid, Dateandtime) so sql has to sort/scan; add at least an index on Wakeups(Dateandtime) + Deviceid later. but i’d try the single query + AsNoTracking() first it usually drops 80s → a few secs (or less)...