How
Marco Cecconi
Twitter: @sklivvz Blog: http://sklivvz.com
does architecture
Architecture:
- the art or science of building; specifically : the art or practice of designing and building structures and especially habitable ones
- Durability
- Utility
- Beauty
Performance:
- (efficiency) the ability to do something or produce something without wasting materials, time, or energy
build
measure
analyze
Stack Exchange network (sites)
Stack Exchange network (pageviews)
Stack Exchange network (web servers)
build
measure
analyze
Build
Measure
Analyze
https://stackexchange.com/performance
build
measure
analyze
public static List<HelpPost> All()
{
return Current
.GlobalCache
.GetSet<List<HelpPost>>(
CacheKey,
(old, ctx) =>
{
using (SitesDBContext sitesDb = SitesDBContext.NewContext())
{
return sitesDb.Query<HelpPost>(@"
SELECT p.Id, p.Title, p.Body, p.DeletionDate, p.SiteId,
p.SitePostId, p.IsModEditable, p.ParentHelpPostId,
p.CreationDate, p.PinnedDate, p.LastEditDate, p.Slug,
p.HelpPostTypeId, p.Subtitle, p.LCID,
c.Id AS CategoryId, c.Rank AS CategoryRank
FROM
HelpPosts p LEFT JOIN
HelpCategories c
ON p.HelpCategoryId = c.Id
WHERE DeletionDate IS NULL");
}
}, 24 * 60 * 60, 24 * 60 * 60, server: StackRedis.Server.PreferSlave);
}
Build
Measure
Analyze
Production Deployments per day
public static List<HelpPost> All()
{
return Current
.GlobalCache
.GetSet<List<HelpPost>>(
CacheKey,
(old, ctx) =>
{
using (SitesDBContext sitesDb = SitesDBContext.NewContext())
{
return sitesDb.Query<HelpPost>(@"
SELECT p.Id, p.Title, p.Body, p.DeletionDate, p.SiteId,
p.SitePostId, p.IsModEditable, p.ParentHelpPostId,
p.CreationDate, p.PinnedDate, p.LastEditDate, p.Slug,
p.HelpPostTypeId, p.Subtitle, p.LCID,
c.Id AS CategoryId, c.Rank AS CategoryRank
FROM
HelpPosts p LEFT JOIN
HelpCategories c
ON p.HelpCategoryId = c.Id
WHERE DeletionDate IS NULL");
}
}, 24 * 60 * 60, 24 * 60 * 60, server: StackRedis.Server.PreferSlave);
}
@Html.Partial("~/Views/Shared/PageTabs.cshtml", new StackOverflow.Views.Shared.PageTabs
{
Tabs = Current.LocalCache.GetSet<List<TabItem>>("question-show-tabs",
(_1,_2) => new List<TabItem>
{
new TabItem
{
Value = ShowViewData.Tab.Active,
Title = _s("active"),
Description = _s("Answers with the latest activity first"),
KeyboardShortcut = "A"
},
new TabItem
{
Value = ShowViewData.Tab.Oldest,
Title = _s("oldest"),
Description = _s("Answers in the order they were provided"),
KeyboardShortcut = "O"
},
new TabItem
{
Value = ShowViewData.Tab.Votes,
Title = _s("votes"),
Description = _s("Answers with the highest score first"),
KeyboardShortcut="V"
},
}, 24 * 60 * 60, 24 * 60 * 60),
UrlFormat = Question.UrlRelative + "?answertab={0}#tab-top",
CurrentSelection = Model.CurrentTab
})
@Html.Partial("~/Views/Shared/PageTabs.cshtml", new StackOverflow.Views.Shared.PageTabs
{
Tabs = Current.LocalCache.GetSet<List<TabItem>>("question-show-tabs",
(_1,_2) => new List<TabItem>
{
new TabItem
{
Value = ShowViewData.Tab.Active,
Title = _s("active"),
Description = _s("Answers with the latest activity first"),
KeyboardShortcut = "A"
},
new TabItem
{
Value = ShowViewData.Tab.Oldest,
Title = _s("oldest"),
Description = _s("Answers in the order they were provided"),
KeyboardShortcut = "O"
},
new TabItem
{
Value = ShowViewData.Tab.Votes,
Title = _s("votes"),
Description = _s("Answers with the highest score first"),
KeyboardShortcut="V"
},
}, 24 * 60 * 60, 24 * 60 * 60),
UrlFormat = Question.UrlRelative + "?answertab={0}#tab-top",
CurrentSelection = Model.CurrentTab
})
<p>
@_s("Privileges control what you can do on $ShortName$. " +
"Gain more privileges by increasing your reputation " +
"(points you receive from your fellow users for posting" +
" helpful questions and answers).", Current.Site)
</p>
Dependency Injection
var repository = container.Resolve<IRepository<Order>>();
Order order = repository.Get(25);
public IRepository<T> Resolve<T>()
{
var data = new NHibernateRepository<T>();
var cache = new CachingRepository<T>(data);
var log = new LoggingRepository<T>(cache);
var sec = new SecurityRepository<T>(log);
var valid = new ValidatingRepository<T>(sec);
return valid;
}
build
measure
analyze
Build
Measure
Analyze
build
measure
analyze
people
tools
code
Build
Measure
Analyze
Conclusion
- Performance is a feature, not a luxury
- Performance is optimized in cycles
- The results are very specific to your case...
- ...but also extremely high-value
- Garbage collection is a pain
- Hire hackers...
- ...and buy them those 3 monitors already!
High perf architecture
By Marco Cecconi
High perf architecture
- 1,585