fix for disk job queue size measurement
This commit is contained in:
parent
67110ec0a3
commit
9109af0ce1
|
@ -433,6 +433,9 @@ namespace libtorrent
|
||||||
// average read time for cache misses (in microseconds)
|
// average read time for cache misses (in microseconds)
|
||||||
sliding_average<512> m_read_time;
|
sliding_average<512> m_read_time;
|
||||||
|
|
||||||
|
typedef std::multimap<size_type, disk_io_job> read_jobs_t;
|
||||||
|
read_jobs_t m_sorted_read_jobs;
|
||||||
|
|
||||||
#ifdef TORRENT_DISK_STATS
|
#ifdef TORRENT_DISK_STATS
|
||||||
std::ofstream m_log;
|
std::ofstream m_log;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -433,7 +433,7 @@ namespace libtorrent
|
||||||
|
|
||||||
ret.average_queue_time = m_queue_time.mean();
|
ret.average_queue_time = m_queue_time.mean();
|
||||||
ret.average_read_time = m_read_time.mean();
|
ret.average_read_time = m_read_time.mean();
|
||||||
ret.job_queue_length = m_jobs.size();
|
ret.job_queue_length = m_jobs.size() + m_read_jobs.size();
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -1523,9 +1523,7 @@ namespace libtorrent
|
||||||
// 1 = forward in list, -1 = backwards in list
|
// 1 = forward in list, -1 = backwards in list
|
||||||
int elevator_direction = 1;
|
int elevator_direction = 1;
|
||||||
|
|
||||||
typedef std::multimap<size_type, disk_io_job> read_jobs_t;
|
read_jobs_t::iterator elevator_job_pos = m_sorted_read_jobs.begin();
|
||||||
read_jobs_t sorted_read_jobs;
|
|
||||||
read_jobs_t::iterator elevator_job_pos = sorted_read_jobs.begin();
|
|
||||||
size_type last_elevator_pos = 0;
|
size_type last_elevator_pos = 0;
|
||||||
bool need_update_elevator_pos = false;
|
bool need_update_elevator_pos = false;
|
||||||
|
|
||||||
|
@ -1536,7 +1534,7 @@ namespace libtorrent
|
||||||
#endif
|
#endif
|
||||||
mutex::scoped_lock jl(m_queue_mutex);
|
mutex::scoped_lock jl(m_queue_mutex);
|
||||||
|
|
||||||
while (m_jobs.empty() && sorted_read_jobs.empty() && !m_abort)
|
while (m_jobs.empty() && m_sorted_read_jobs.empty() && !m_abort)
|
||||||
{
|
{
|
||||||
// if there hasn't been an event in one second
|
// if there hasn't been an event in one second
|
||||||
// see if we should flush the cache
|
// see if we should flush the cache
|
||||||
|
@ -1633,8 +1631,8 @@ namespace libtorrent
|
||||||
m_log << log_time() << " sorting_job" << std::endl;
|
m_log << log_time() << " sorting_job" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
size_type phys_off = j.storage->physical_offset(j.piece, j.offset);
|
size_type phys_off = j.storage->physical_offset(j.piece, j.offset);
|
||||||
need_update_elevator_pos = need_update_elevator_pos || sorted_read_jobs.empty();
|
need_update_elevator_pos = need_update_elevator_pos || m_sorted_read_jobs.empty();
|
||||||
sorted_read_jobs.insert(std::pair<size_type, disk_io_job>(phys_off, j));
|
m_sorted_read_jobs.insert(std::pair<size_type, disk_io_job>(phys_off, j));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1645,31 +1643,31 @@ namespace libtorrent
|
||||||
// job queue lock anymore
|
// job queue lock anymore
|
||||||
jl.unlock();
|
jl.unlock();
|
||||||
|
|
||||||
TORRENT_ASSERT(!sorted_read_jobs.empty());
|
TORRENT_ASSERT(!m_sorted_read_jobs.empty());
|
||||||
|
|
||||||
// if sorted_read_jobs used to be empty,
|
// if m_sorted_read_jobs used to be empty,
|
||||||
// we need to update the elevator position
|
// we need to update the elevator position
|
||||||
if (need_update_elevator_pos)
|
if (need_update_elevator_pos)
|
||||||
{
|
{
|
||||||
elevator_job_pos = sorted_read_jobs.lower_bound(last_elevator_pos);
|
elevator_job_pos = m_sorted_read_jobs.lower_bound(last_elevator_pos);
|
||||||
need_update_elevator_pos = false;
|
need_update_elevator_pos = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we've reached the end, change the elevator direction
|
// if we've reached the end, change the elevator direction
|
||||||
if (elevator_job_pos == sorted_read_jobs.end())
|
if (elevator_job_pos == m_sorted_read_jobs.end())
|
||||||
{
|
{
|
||||||
elevator_direction = -1;
|
elevator_direction = -1;
|
||||||
--elevator_job_pos;
|
--elevator_job_pos;
|
||||||
}
|
}
|
||||||
TORRENT_ASSERT(!sorted_read_jobs.empty());
|
TORRENT_ASSERT(!m_sorted_read_jobs.empty());
|
||||||
|
|
||||||
TORRENT_ASSERT(elevator_job_pos != sorted_read_jobs.end());
|
TORRENT_ASSERT(elevator_job_pos != m_sorted_read_jobs.end());
|
||||||
j = elevator_job_pos->second;
|
j = elevator_job_pos->second;
|
||||||
read_jobs_t::iterator to_erase = elevator_job_pos;
|
read_jobs_t::iterator to_erase = elevator_job_pos;
|
||||||
|
|
||||||
// if we've reached the begining of the sorted list,
|
// if we've reached the begining of the sorted list,
|
||||||
// change the elvator direction
|
// change the elvator direction
|
||||||
if (elevator_job_pos == sorted_read_jobs.begin())
|
if (elevator_job_pos == m_sorted_read_jobs.begin())
|
||||||
elevator_direction = 1;
|
elevator_direction = 1;
|
||||||
|
|
||||||
// move the elevator before erasing the job we're processing
|
// move the elevator before erasing the job we're processing
|
||||||
|
@ -1679,7 +1677,7 @@ namespace libtorrent
|
||||||
|
|
||||||
TORRENT_ASSERT(to_erase != elevator_job_pos);
|
TORRENT_ASSERT(to_erase != elevator_job_pos);
|
||||||
last_elevator_pos = to_erase->first;
|
last_elevator_pos = to_erase->first;
|
||||||
sorted_read_jobs.erase(to_erase);
|
m_sorted_read_jobs.erase(to_erase);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if there's a buffer in this job, it will be freed
|
// if there's a buffer in this job, it will be freed
|
||||||
|
@ -1795,8 +1793,8 @@ namespace libtorrent
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
// now clear all the read jobs
|
// now clear all the read jobs
|
||||||
for (read_jobs_t::iterator i = sorted_read_jobs.begin();
|
for (read_jobs_t::iterator i = m_sorted_read_jobs.begin();
|
||||||
i != sorted_read_jobs.end();)
|
i != m_sorted_read_jobs.end();)
|
||||||
{
|
{
|
||||||
if (i->second.storage != j.storage)
|
if (i->second.storage != j.storage)
|
||||||
{
|
{
|
||||||
|
@ -1805,7 +1803,7 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
post_callback(i->second.callback, i->second, -3);
|
post_callback(i->second.callback, i->second, -3);
|
||||||
if (elevator_job_pos == i) ++elevator_job_pos;
|
if (elevator_job_pos == i) ++elevator_job_pos;
|
||||||
sorted_read_jobs.erase(i++);
|
m_sorted_read_jobs.erase(i++);
|
||||||
}
|
}
|
||||||
jl.unlock();
|
jl.unlock();
|
||||||
|
|
||||||
|
@ -1858,8 +1856,8 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
jl.unlock();
|
jl.unlock();
|
||||||
|
|
||||||
for (read_jobs_t::iterator i = sorted_read_jobs.begin();
|
for (read_jobs_t::iterator i = m_sorted_read_jobs.begin();
|
||||||
i != sorted_read_jobs.end();)
|
i != m_sorted_read_jobs.end();)
|
||||||
{
|
{
|
||||||
if (i->second.storage != j.storage)
|
if (i->second.storage != j.storage)
|
||||||
{
|
{
|
||||||
|
@ -1868,7 +1866,7 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
post_callback(i->second.callback, i->second, -3);
|
post_callback(i->second.callback, i->second, -3);
|
||||||
if (elevator_job_pos == i) ++elevator_job_pos;
|
if (elevator_job_pos == i) ++elevator_job_pos;
|
||||||
sorted_read_jobs.erase(i++);
|
m_sorted_read_jobs.erase(i++);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_abort = true;
|
m_abort = true;
|
||||||
|
|
Loading…
Reference in New Issue