Skip to content

Commit 98fd175

Browse files
authored
Merge pull request #5868 from wangyoucao577/feature/unify-turn-index-dump
Unify .osrm.turn_penalties_index dump same with turn_weight_penalties/turn_duration_penalties
2 parents 21444ce + 17eb39d commit 98fd175

File tree

4 files changed

+33
-35
lines changed

4 files changed

+33
-35
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Unreleased
22
- Changes from 5.23.0
3+
- Misc:
4+
- CHANGED: Unify `.osrm.turn_penalites_index` dump processing same with `.osrm.turn_weight_penalties` and `.osrm.turn_duration_penalties` [#5868](https://github.com/Project-OSRM/osrm-backend/pull/5868)
35
- Infrastructure
46
- CHANGED: Bundled protozero updated to v1.7.0. [#5858](https://github.com/Project-OSRM/osrm-backend/pull/5858)
57
- Windows:

include/extractor/files.hpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,28 @@ inline void readTurnDurationPenalty(const boost::filesystem::path &path, TurnPen
399399
storage::serialization::read(reader, "/common/turn_penalty/duration", turn_penalty);
400400
}
401401

402+
// writes .osrm.turn_penalties_index
403+
template <typename TurnIndexT>
404+
inline void writeTurnPenaltiesIndex(const boost::filesystem::path &path,
405+
const TurnIndexT &turn_penalties_index)
406+
{
407+
const auto fingerprint = storage::tar::FileWriter::GenerateFingerprint;
408+
storage::tar::FileWriter writer{path, fingerprint};
409+
410+
storage::serialization::write(writer, "/extractor/turn_index", turn_penalties_index);
411+
}
412+
413+
// read .osrm.turn_penalties_index
414+
template <typename TurnIndexT>
415+
inline void readTurnPenaltiesIndex(const boost::filesystem::path &path,
416+
TurnIndexT &turn_penalties_index)
417+
{
418+
const auto fingerprint = storage::tar::FileReader::VerifyFingerprint;
419+
storage::tar::FileReader reader{path, fingerprint};
420+
421+
storage::serialization::read(reader, "/extractor/turn_index", turn_penalties_index);
422+
}
423+
402424
// writes .osrm.restrictions
403425
template <typename ConditionalRestrictionsT>
404426
inline void writeConditionalRestrictions(const boost::filesystem::path &path,

src/extractor/edge_based_graph_factory.cpp

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ template <> struct hash<std::pair<NodeID, NodeID>>
5353
};
5454
}
5555

56-
// Buffer size of turn_indexes_write_buffer to reduce number of write(v) syscals
57-
const constexpr int TURN_INDEX_WRITE_BUFFER_SIZE = 1000;
58-
5956
namespace osrm
6057
{
6158
namespace extractor
@@ -449,10 +446,6 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
449446

450447
std::size_t node_based_edge_counter = 0;
451448

452-
storage::tar::FileWriter turn_penalties_index_file(
453-
turn_penalties_index_filename, storage::tar::FileWriter::GenerateFingerprint);
454-
turn_penalties_index_file.WriteFrom("/extractor/turn_index", (char *)nullptr, 0);
455-
456449
SuffixTable street_name_suffix_table(scripting_environment);
457450
const auto &turn_lanes_data = transformTurnLaneMapIntoArrays(lane_description_map);
458451
intersection::MergableRoadDetector mergable_road_detector(m_node_based_graph,
@@ -468,6 +461,7 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
468461
// FIXME these need to be tuned in pre-allocated size
469462
std::vector<TurnPenalty> turn_weight_penalties;
470463
std::vector<TurnPenalty> turn_duration_penalties;
464+
std::vector<lookup::TurnIndexBlock> turn_penalties_index;
471465

472466
// Now, renumber all our maneuver overrides to use edge-based-nodes
473467
std::vector<StorageManeuverOverride> storage_maneuver_overrides;
@@ -487,14 +481,6 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
487481
{
488482
const NodeID node_count = m_node_based_graph.GetNumberOfNodes();
489483

490-
// Because we write TurnIndexBlock data as we go, we'll
491-
// buffer them into groups of 1000 to reduce the syscall
492-
// count by 1000x. This doesn't need much memory, but
493-
// greatly reduces the syscall overhead of writing lots
494-
// of small objects
495-
std::vector<lookup::TurnIndexBlock> turn_indexes_write_buffer;
496-
turn_indexes_write_buffer.reserve(TURN_INDEX_WRITE_BUFFER_SIZE);
497-
498484
// This struct is the buffered output of the `processor_stage`. This data is
499485
// appended to the various output arrays/files by the `output_stage`.
500486
// same as IntersectionData, but grouped with edge to allow sorting after creating.
@@ -510,7 +496,7 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
510496
m_edge_based_edge_list.push_back(edge_with_data.edge);
511497
turn_weight_penalties.push_back(edge_with_data.turn_weight_penalty);
512498
turn_duration_penalties.push_back(edge_with_data.turn_duration_penalty);
513-
turn_indexes_write_buffer.push_back(edge_with_data.turn_index);
499+
turn_penalties_index.push_back(edge_with_data.turn_index);
514500
};
515501

516502
struct EdgesPipelineBuffer
@@ -1054,15 +1040,6 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
10541040
// NOTE: potential overflow here if we hit 2^32 routable edges
10551041
BOOST_ASSERT(m_edge_based_edge_list.size() <= std::numeric_limits<NodeID>::max());
10561042

1057-
// Buffer writes to reduce syscall count
1058-
if (turn_indexes_write_buffer.size() >= TURN_INDEX_WRITE_BUFFER_SIZE)
1059-
{
1060-
turn_penalties_index_file.ContinueFrom("/extractor/turn_index",
1061-
turn_indexes_write_buffer.data(),
1062-
turn_indexes_write_buffer.size());
1063-
turn_indexes_write_buffer.clear();
1064-
}
1065-
10661043
// Copy via-way restrictions delayed data
10671044
delayed_data.insert(
10681045
delayed_data.end(), buffer->delayed_data.begin(), buffer->delayed_data.end());
@@ -1118,15 +1095,6 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
11181095

11191096
storage_maneuver_overrides.push_back(storage_override);
11201097
}
1121-
1122-
// Flush the turn_indexes_write_buffer if it's not empty
1123-
if (!turn_indexes_write_buffer.empty())
1124-
{
1125-
turn_penalties_index_file.ContinueFrom("/extractor/turn_index",
1126-
turn_indexes_write_buffer.data(),
1127-
turn_indexes_write_buffer.size());
1128-
turn_indexes_write_buffer.clear();
1129-
}
11301098
}
11311099
{
11321100
util::Log() << "Sorting and writing " << storage_maneuver_overrides.size()
@@ -1162,9 +1130,11 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
11621130
indexed_conditionals);
11631131

11641132
// write weight penalties per turn
1165-
BOOST_ASSERT(turn_weight_penalties.size() == turn_duration_penalties.size());
1133+
BOOST_ASSERT(turn_weight_penalties.size() == turn_duration_penalties.size() &&
1134+
turn_weight_penalties.size() == turn_penalties_index.size());
11661135
files::writeTurnWeightPenalty(turn_weight_penalties_filename, turn_weight_penalties);
11671136
files::writeTurnDurationPenalty(turn_duration_penalties_filename, turn_duration_penalties);
1137+
files::writeTurnPenaltiesIndex(turn_penalties_index_filename, turn_penalties_index);
11681138

11691139
util::Log() << "Generated " << m_edge_based_node_segments.size() << " edge based node segments";
11701140
util::Log() << "Node-based graph contains " << node_based_edge_counter << " edges";

src/updater/updater.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,10 @@ updateTurnPenalties(const UpdaterConfig &config,
432432
{
433433
const auto weight_multiplier = profile_properties.GetWeightMultiplier();
434434

435+
// [NOTE] turn_index_blocks could be simply loaded by `files::readTurnPenaltiesIndex()`,
436+
// however, we leave the below mmap to keep compatiblity.
437+
// Use `files::readTurnPenaltiesIndex()` instead once the compatiblity is not that
438+
// important.
435439
// Mapped file pointer for turn indices
436440
boost::iostreams::mapped_file_source turn_index_region;
437441
const extractor::lookup::TurnIndexBlock *turn_index_blocks;

0 commit comments

Comments
 (0)