fixed: as we have insert_page ezc function now

we cannot delete ezc patterns when PatternCacher::GetPattern() method is called
       because we can delete a pattern which is in use
       now deleting is performed at the end of a request


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@751 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2011-07-15 02:09:02 +00:00
parent 1812a2e9ad
commit c37c1ff812
9 changed files with 108 additions and 54 deletions

View File

@ -143,11 +143,7 @@ bool App::Init()
compress.Init();
system.Init();
functions.Init();
// init templates after functions are created
templates.CreateFunctions(); // create functions first (functions will be cached by patterns)
templates.ReadIndexFileNames();
templates.ReadTemplates();
templates.Init(); // init templates after functions are created
// init notify after templates (it uses locales from templates)
system.notify.ReadTemplates();
@ -237,7 +233,6 @@ void App::ProcessRequest()
SaveSessionsIfNeeded(); // !! przerzucic to na watek sesji
system.load_avg.StopRequest();
log << logendrequest;
}
catch(const std::exception & e)
{
@ -259,12 +254,14 @@ void App::ProcessRequest()
}
catch(...)
{
log << log1 << "App: an exception when clearing the request (from a plugin)" << logend;
log << log1 << "App: an exception when clearing after a request (exception from a plugin)" << logend;
}
// simple operations which should not throw an exception
templates.RequestEnd();
cur.request->Clear();
cur.session = session_manager.GetTmpSession();
log << logendrequest;
}

View File

@ -82,25 +82,17 @@ public:
model
*/
// file system
// ...
System system;
// functions (ls, cat, emacs, ...)
Functions functions;
// false at the beginning
// !! moze to do loggera dac?
bool stdout_is_closed;
/*
controllers
(note that the whole app object is actually a controller too)
*/
// functions (ls, cat, emacs, ...)
Functions functions;
/*
view
*/

View File

@ -207,6 +207,9 @@ void Config::AssignValues(bool stdout_is_closed)
pass_rsa_private_key = Text(L"pass_rsa_private_key");
opensll_path = Text(L"opensll_path", L"/usr/bin/openssl");
pattern_cacher_when_delete = Size(L"pattern_cacher_when_delete", 130);
pattern_cacher_how_many_delete = Size(L"pattern_cacher_how_many_delete", 30);
}

View File

@ -378,11 +378,18 @@ public:
// !! once you set these keys don't change it any more (people wouldn't be allowed to login)
std::wstring pass_rsa_private_key;
// path to 'openssl'
// default: /usr/bin/openssl
std::wstring opensll_path;
// setting when we should delete patterns (EZC patterns)
// we are deleting when we have more (or equal) patterns than 'when_delete'
// and then we are deleting 'how_many_del' patterns
// those patterns comes from items (pages) with executable bit set
size_t pattern_cacher_when_delete;
size_t pattern_cacher_how_many_delete;
/*
*/

View File

@ -41,7 +41,7 @@ void insert_page_run(Info & i)
InsertPageInfo & info = insert_page_info[insert_page_cur];
Ezc::Pattern * pat = pattern_cacher.GetPattern(info.item);
log << "insert page: using " << insert_page_cur << " generator" << logend;
log << log4 << "Templates: insert_page_run: using " << insert_page_cur << " generator" << logend;
insert_page_cur += 1;
info.run_content.Clear();
@ -58,8 +58,6 @@ bool insert_page_init(const std::wstring & path)
if( path.empty() )
return false;
log << "insert page: " << path << logend;
if( insert_page_reqid != cur->request->id )
{
insert_page_reqid = cur->request->id;
@ -68,7 +66,7 @@ bool insert_page_init(const std::wstring & path)
if( insert_page_cur >= WINIX_TEMPLATES_INSERT_PAGE_MAX )
{
log << log1 << "Templates: insert_page: maximum nested insert_page exceeded" << logend;
log << log1 << "Templates: insert_page: maximum nested insert_page functions exceeded" << logend;
return false;
}

View File

@ -2,7 +2,7 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* Copyright (c) 2008-2011, Tomasz Sowa
* All rights reserved.
*
*/
@ -14,10 +14,8 @@
PatternCacher::PatternCacher()
{
// !! tymczasowe wartosci dla testow
when_delete_patterns = 3; // 130
how_many_delete = 2; // 30
when_delete_patterns = 13;
how_many_delete = 3;
ezc_fun = 0;
}
@ -28,7 +26,15 @@ void PatternCacher::SetEzcFunctions(TemplatesFunctions::EzcFun * fun)
}
void PatternCacher::CheckTableSize()
void PatternCacher::SetWhenDelete(size_t when_delete, size_t how_many_del)
{
when_delete_patterns = when_delete;
how_many_delete = how_many_del;
}
void PatternCacher::DeleteOldPatterns()
{
if( pattern_tab.size() < when_delete_patterns )
return;
@ -52,7 +58,10 @@ void PatternCacher::CheckTableSize()
for(erase_index = 0 ; erase_index<how_many_delete && erase_index<erase_tab.size() ; ++erase_index)
{
log << log2 << "PC: deleting from cache, id: " << erase_tab[erase_index].iter->second.item_id << logend;
log << log2 << "PC: deleting ezc pattern from the cache, id: "
<< erase_tab[erase_index].iter->second.item_id
<< ", item used: " << erase_tab[erase_index].used << " time(s)"
<< logend;
pattern_tab.erase(erase_tab[erase_index].iter);
}
@ -73,7 +82,9 @@ void PatternCacher::CreatePattern(const Item & item, Ezc::Pattern & pattern)
Ezc::Pattern * PatternCacher::AddPattern(const Item & item)
{
CheckTableSize();
// don't call DeleteOldPatterns() here
// because you can delete a pattern which is in use
// (think about ezc functions: item run, insert_page etc)
PatternUsed pu;
@ -83,7 +94,7 @@ Ezc::Pattern * PatternCacher::AddPattern(const Item & item)
std::pair<PatternTab::iterator, bool> res = pattern_tab.insert( std::make_pair(item.id, pu) );
log << log2 << "PC: added an item, id: " << item.id << ", url: " << item.url << logend;
log << log2 << "PC: added ezc pattern, item_id: " << item.id << ", url: " << item.url << logend;
return &(res.first->second.pattern);
}
@ -101,7 +112,7 @@ PatternTab::iterator i;
return AddPattern(item);
else
{
log << log2 << "PC: taking a pattern from the cache, id: " << item.id << ", url: " << item.url << logend;
log << log2 << "PC: taking pattern from the cache, id: " << item.id << ", url: " << item.url << logend;
++(i->second.used);
return &(i->second.pattern);
}
@ -141,3 +152,11 @@ PatternTab::iterator i;
pattern_tab.erase(i);
}
size_t PatternCacher::Size()
{
return pattern_tab.size();
}

View File

@ -2,7 +2,7 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* Copyright (c) 2008-2011, Tomasz Sowa
* All rights reserved.
*
*/
@ -23,6 +23,38 @@
class PatternCacher
{
public:
PatternCacher();
// setting when we should delete patterns
// we are deleting when we have more (or equal) patterns than 'when_delete'
// and then we are deleting 'how_many_del' patterns
void SetWhenDelete(size_t when_delete, size_t how_many_del);
void SetEzcFunctions(TemplatesFunctions::EzcFun * fun);
// returning a pattern corresponding to the 'item'
Ezc::Pattern * GetPattern(const Item & item);
// updating the pattern for the item
// if there is no such a pattern the method does nothing
void UpdatePattern(const Item & item);
// deleting the pattern for the item
// if there is no such a pattern the method does nothing
void DeletePattern(const Item & item);
// deleting some rarely used patters
// call it at the end of a request (or at the beginning)
void DeleteOldPatterns();
// size of the current cache in use
size_t Size();
private:
struct PatternUsed
{
Ezc::Pattern pattern;
@ -51,7 +83,6 @@ class PatternCacher
void CreatePattern(const Item & item, Ezc::Pattern & pattern);
void AddIndexes(const Item & item, size_t pattern_index);
Ezc::Pattern * AddPattern(const Item & item);
void CheckTableSize();
// the size of pattern_tab when we are deleting some items
@ -63,22 +94,6 @@ class PatternCacher
// can be null (not set directly)
TemplatesFunctions::EzcFun * ezc_fun;
public:
PatternCacher();
void SetEzcFunctions(TemplatesFunctions::EzcFun * fun);
// returning a pattern corresponding to the 'item'
Ezc::Pattern * GetPattern(const Item & item);
// updating the pattern for the item
// if there is no such a pattern the method does nothing
void UpdatePattern(const Item & item);
// deleting the pattern for the item
// if there is no such a pattern the method does nothing
void DeletePattern(const Item & item);
};
#endif

View File

@ -674,6 +674,17 @@ size_t loc, pat;
}
void Templates::Init()
{
using namespace TemplatesFunctions;
pattern_cacher.SetWhenDelete(config->pattern_cacher_when_delete, config->pattern_cacher_how_many_delete);
CreateFunctions(); // create functions first (functions will be cached by patterns)
ReadIndexFileNames();
ReadTemplates();
}
// index_patterns and patterns for items are not cleared here
void Templates::ClearPatterns()
{
@ -684,6 +695,16 @@ using namespace TemplatesFunctions;
}
// clearing at the end of a request
void Templates::RequestEnd()
{
using namespace TemplatesFunctions;
log << log4 << "Templates: patterns cache size: " << pattern_cacher.Size() << logend;
pattern_cacher.DeleteOldPatterns();
}
void Templates::Generate()
{
using namespace TemplatesFunctions;

View File

@ -438,11 +438,12 @@ public:
void SetFunctions(Functions * pfunctions);
void SetSessionManager(SessionManager * psession_manager);
void Init();
void ClearPatterns();
void RequestEnd();
void ReadTemplates();
void ReadNewIndexTemplates();
void ReadIndexFileNames(bool add_pattern = false);
void CreateFunctions(); // should be called before reading patterns (patterns will cache ezc functions)
void Generate();
void GenerateRunRaw();
void Generate(Ezc::Pattern & pattern);
@ -455,6 +456,7 @@ private:
void SetLocale();
void SetHtmlFilter();
void ClearPatterns(TemplatesFunctions::Patterns & patterns, size_t len);
void CreateFunctions(); // should be called before reading patterns (patterns will cache ezc functions)
TemplatesFunctions::EzcGen generator;
std::wstring temp;