2011-08-25 24 views
5

Tôi đang sử dụng Mvc-Mini-Profiler (một sản phẩm tuyệt vời!). Sử dụng trình duyệt web thông thường của tôi, mọi thứ dường như hoạt động tốt nhưng ngay sau khi tôi sử dụng máy khách http của riêng mình (cơ bản http 1.1 không hỗ trợ cookie), số lượng X-MiniProfiler-Ids trong tiêu đề http tăng. Điều này xảy ra khá nhanh và trở nên khá nhiều trong một khoảng thời gian ngắn (11kB và cao hơn dữ liệu).Mvc-Mini-Profiler: Tại sao có quá nhiều X-MiniProfiler-Id?

Việc thiếu cookie có làm cho Mvc-Mini-Profiler hoạt động theo cách này hoặc có thể xảy ra sự cố với việc triển khai của tôi không?

Trả lời

6

Đây là thiết kế mà tôi nghĩ. Mặc dù chúng tôi có thể cải thiện việc triển khai một chút.

Cần phải "tiêu thụ" X-MiniProfiler-Ids, chúng chỉ hiển thị khi bật hồ sơ. Lý do nó hoạt động theo cách này là để bạn có thể cấu hình POST và chuyển hướng.

Có lẽ chúng tôi nên đặt một số giới hạn trên rõ ràng ở đó (như 20 hoặc hơn) - vui lòng đăng lỗi cho điều đó.

Tuy nhiên, vì bạn không bao giờ thực sự có kế hoạch tiêu thụ bất kỳ khối lược tả nào cho ứng dụng khách HTTP, tôi khuyên bạn nên bỏ qua hồ sơ nếu useragent là ứng dụng khách HTTP của bạn.

Bạn có thể làm điều này bằng cách thêm một điều kiện trước:

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

Cảm ơn, lỗi được báo cáo là [# 99] (http://code.google.com/p/mvc-mini-profiler/issues/detail?id=99) –

1

lựa chọn khác là để ghi đè lên lớp SqlServerStorage và mặc định lĩnh vực UserHasViewed là true. Điều này sẽ giữ chuỗi X-MiniProfiler-Id xuống mức tối thiểu.

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

giải pháp Clever, nhưng điều này không đòi hỏi tôi sử dụng một lưu trữ sql? Ngoài ra, điều này ngăn cản các tác nhân người dùng có thể xử lý một số lượng lớn x-mini-profiler-id từ hoạt động "bình thường". –

+0

Cách tiếp cận này có thể được sử dụng để ghi đè MemoryStorage, tôi vừa mới đăng mã này từ dự án của tôi. Tuy nhiên, lưu trữ dữ liệu trong một cơ sở dữ liệu không có lợi thế của nó [MVC Mini Profiler Dashboard] (http://code.google.com/p/mvc-mini-profiler-dashboard/). –

+0

Để trả lời câu hỏi thứ hai của bạn: Có, nó sẽ ngăn chặn chức năng bình thường trên các máy khách có thể xử lý số lượng lớn các id x-mini-profiler. Tùy chọn khác của bạn sẽ là ngã ba Mvc-mini-profiler và sửa chữa mã gốc hoặc loại bỏ tiêu đề x-mini-profiler-id cho các máy khách không thể hỗ trợ chúng :( –

Các vấn đề liên quan