2011-08-25 10 views
5

Sto usando Mvc-Mini-Profiler (che bel prodotto!). Usando il mio normale browser web tutto sembra funzionare bene ma non appena utilizzo il mio client http (http di base 1.1 senza supporto per i cookie) la quantità di X-MiniProfiler-Ids nell'intestazione http aumenta. Questo accade abbastanza rapidamente e diventa abbastanza veloce in un breve lasso di tempo (11kB e oltre di dati).Mvc-Mini-Profiler: perché tanti X-MiniProfiler-Ids?

Può la mancanza di cookie rendere Mvc-Mini-Profiler funzionare in questo modo o potrebbe essere qualcosa di sbagliato nella mia implementazione?

risposta

6

Questo è di progettazione, penso. Anche se potremmo migliorare un po 'l'implementazione.

Gli X-MiniProfiler-Ids devono essere "consumati", vengono visualizzati solo quando è abilitata la profilazione. Il motivo per cui funziona in questo modo è che puoi profilare il profilo POST e reindirizzare.

Probabilmente dovremmo impostare un limite superiore chiaro (come 20 o giù di lì) - per favore, invia un bug per questo.

Tuttavia, dal momento che non si prevede realmente di utilizzare blocchi di profiling per il client HTTP, è consigliabile abbandonare il profilo se l'useragent è il client HTTP.

si può fare questo con l'aggiunta di un condizionale prima:

// don't run if UserAgent is "my http client" 
if(notMyUserAgent) 
    MvcMiniProfiler.MiniProfiler.Start(); 
+0

Grazie, bug segnalati come [# 99] (http://code.google.com/p/mvc-mini-profiler/issues/detail?id=99) –

1

Un'altra opzione è quella di sostituire la classe SqlServerStorage e di default il campo UserHasViewed su true. Ciò manterrà la stringa X-MiniProfiler-Id al minimo.

public class MvcMiniProfilerStorage : SqlServerStorage 
{ 
    public MvcMiniProfilerStorage(string connectionString) : base(connectionString) 
    { 
    } 

    /// <summary> 
    ///  Stores to dbo.MiniProfilers under its ; 
    ///  stores all child Timings and SqlTimings to their respective tables. 
    /// </summary> 
    public override void Save(MiniProfiler profiler) 
    { 
     const string sql = 
      @"insert into MiniProfilers 
     (Id, 
     Name, 
     Started, 
     MachineName, 
     [User], 
     Level, 
     RootTimingId, 
     DurationMilliseconds, 
     DurationMillisecondsInSql, 
     HasSqlTimings, 
     HasDuplicateSqlTimings, 
     HasTrivialTimings, 
     HasAllTrivialTimings, 
     TrivialDurationThresholdMilliseconds, 
     HasUserViewed) 
select  @Id, 
     @Name, 
     @Started, 
     @MachineName, 
     @User, 
     @Level, 
     @RootTimingId, 
     @DurationMilliseconds, 
     @DurationMillisecondsInSql, 
     @HasSqlTimings, 
     @HasDuplicateSqlTimings, 
     @HasTrivialTimings, 
     @HasAllTrivialTimings, 
     @TrivialDurationThresholdMilliseconds, 
     @HasUserViewed 
where not exists (select 1 from MiniProfilers where Id = @Id)"; 
     // this syntax works on both mssql and sqlite 

     using (DbConnection conn = GetOpenConnection()) 
     { 
      int insertCount = conn.Execute(sql, 
       new 
        { 
         profiler.Id, 
         Name = Truncate(profiler.Name, 200), 
         profiler.Started, 
         MachineName = Truncate(profiler.MachineName, 100), 
         User = Truncate(profiler.User, 100), 
         profiler.Level, 
         RootTimingId = profiler.Root.Id, 
         profiler.DurationMilliseconds, 
         profiler.DurationMillisecondsInSql, 
         profiler.HasSqlTimings, 
         profiler.HasDuplicateSqlTimings, 
         profiler.HasTrivialTimings, 
         profiler.HasAllTrivialTimings, 
         profiler.TrivialDurationThresholdMilliseconds, 
         // BUG: Too many X-MiniProfiler-Id headers cause 
         // Firefox to stop all requests 
         // 
         // This hack marks all entries as read so that 
         // they do not end up part of that header. 
         HasUserViewed = true 
        }); 

      if (insertCount > 0) 
      { 
       SaveTiming(conn, profiler, profiler.Root); 
      } 
     } 
    } 

    private static string Truncate(string s, int maxLength) 
    { 
     return s != null && s.Length > 
        maxLength ? s.Substring(0, maxLength) : s; 
    } 
} 
+0

soluzione intelligente, ma fa questo richiede io per usare un archivio SQL? Inoltre, questo impedisce agli user agent di gestire una grande quantità di x-mini-profiler-ids dal normale funzionamento. –

+0

Questo approccio potrebbe essere usato per sovrascrivere anche il MemoryStorage, mi è appena capitato di postare questo codice dal mio progetto. Tuttavia, la memorizzazione dei dati in un database ha i suoi vantaggi [MVC Mini Profiler Dashboard] (http://code.google.com/p/mvc-mini-profiler-dashboard/). –

+0

Per rispondere alla seconda domanda: Sì, impedirebbe la normale funzionalità sui client che possono gestire il gran numero di x-mini-profiler-id. L'altra opzione sarebbe quella di forgiare Mvc-mini-profiler e correggere il codice originale o rimuovere le intestazioni x-mini-profiler-id per i client che non possono supportarle :( –

Problemi correlati