步骤 | 平均耗费时间(每篇文章) | 顺序 | 注释 |
一,读取文章 | 很快, 5毫秒 | 按文章ID顺序读取 |
|
二,分析文章 | 较慢, 30毫秒 | 处理顺序无所谓 |
|
三,索引文章 | 较快,8毫秒 | 按文章ID顺序建立索引 | 基于效率上的考虑,顺序建索引的速度快得多,实现上也更简单 |
// 省略....................
//
class FEBIRD_DLL_EXPORT PipelineQueueItem
{
public:
unsigned long plserial;
PipelineTask* task;
PipelineQueueItem(unsigned long plserial, PipelineTask* task)
: plserial(plserial)
, task(task)
{}
PipelineQueueItem()
: plserial(0)
, task(0)
{}
};
// 省略....................
//
namespace {
SAME_NAME_MEMBER_COMPARATOR_EX(Compare_plserial_greater, unsigned long,unsigned long, .plserial, std::greater<unsigned long>)
SAME_NAME_MEMBER_COMPARATOR_EX(Compare_plserial_less , unsigned long,unsigned long, .plserial, std::less <unsigned long>)
}
void PipelineStep::serial_step_do_mid(PipelineQueueItem& item)
{
m_out_queue->push(item);
}
void PipelineStep::serial_step_do_last(PipelineQueueItem& item)
{
if (item.task)
m_owner->destroyTask(item.task);
}
void PipelineStep::run_serial_step(int threadno,
void (PipelineStep::*fdo)(PipelineQueueItem&)
)
{
assert(ple_keep == m_pl_enum);
assert(m_threads.size() == 1);
std::vector<PipelineQueueItem> cache;
// unsigned nCached = 0;
m_plserial = 1;
while (isPrevRunning())
{
PipelineQueueItem item;
if (!m_prev->m_out_queue->pop(item, m_owner->m_queue_timeout))
continue;
#ifdef _DEBUG
assert(item.plserial >= m_plserial);
#else
if (item.plserial < m_plserial)
{
std::ostringstream oss;
oss << "fatal at: " << __FILE__ << ":" << __LINE__
<< ", function=" << BOOST_CURRENT_FUNCTION
<< ", item.plserial=" << item.plserial
<< ", m_plserial=" << m_plserial
;
throw std::runtime_error(oss.str());
}
#endif
if (item.plserial == m_plserial)
{Loop:
if (item.task)
process(0, &item);
(this->*fdo)(item);
++m_plserial;
if (!cache.empty() && (item = cache[0]).plserial == m_plserial)
{
std::pop_heap(cache.begin(), cache.end(), Compare_plserial_greater());
cache.pop_back();
goto Loop;
}
}
else // plserial out of order
{
cache.push_back(item);
std::push_heap(cache.begin(), cache.end(), Compare_plserial_greater());
项目地址:http://code.google.com/p/febird