Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

be able to render the planet with 32gb of RAM #618

Merged
merged 50 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
5f30a30
move OutputObjects to mmap store
cldellow Dec 15, 2023
b918769
treat objects at low zoom specially
cldellow Dec 15, 2023
d7caf10
make more explicit that this is unexpected
cldellow Dec 16, 2023
8dff5bf
extend --materialize-geometries to nodes
cldellow Dec 16, 2023
b86fddc
rejig AttributePair layout
cldellow Dec 16, 2023
a54938e
fix initialization order warning
cldellow Dec 16, 2023
fa5a2bf
add PooledString
cldellow Dec 16, 2023
3eb07c2
add tests for attribute store
cldellow Dec 16, 2023
b3eac99
rejig isHot
cldellow Dec 16, 2023
2784903
teach PooledString to work with std::string
cldellow Dec 16, 2023
efe6af9
use PooledString in AttributePair
cldellow Dec 16, 2023
9394bc7
log timings
cldellow Dec 17, 2023
3020011
AppendVector: an append-only chunked vector
cldellow Dec 17, 2023
330b0a7
fix progress when --store present
cldellow Dec 17, 2023
9d97d30
mutex on RelationScan progress output
cldellow Dec 17, 2023
f9993cf
make NodeStore/WayStore shardable
cldellow Dec 17, 2023
b49b1e7
add minimal SortedNodeStore test
cldellow Dec 17, 2023
e81c6ee
stop using internal linkage for atomics
cldellow Dec 17, 2023
1c4174d
SortedNodeStore: abstract TLS behind storage()
cldellow Dec 17, 2023
99b5912
SortedWayStore: abstract TLS behind storage()
cldellow Dec 17, 2023
f225ebd
SortedNodeStore: support multiple instances
cldellow Dec 17, 2023
6c7917b
SortedWayStorage: support multiple instances
cldellow Dec 17, 2023
5d9ca2b
actually fix the low zoom object collection
cldellow Dec 17, 2023
24b73f1
AppendVector tweaks
cldellow Dec 17, 2023
2a05365
more low zoom fixes
cldellow Dec 17, 2023
00bb73b
implement SortedNodeStore::contains
cldellow Dec 17, 2023
e8be59c
implement SortedWayStore::contains
cldellow Dec 17, 2023
792d1b3
use TileCoordinatesSet
cldellow Dec 17, 2023
2df3081
faster covered tile enumeration
cldellow Dec 17, 2023
b9434f2
add ShardedNodeStore
cldellow Dec 18, 2023
e968b40
add ShardedWayStore
cldellow Dec 18, 2023
4bfca70
fewer, more balanced shards
cldellow Dec 18, 2023
ffbd194
skip ReadPhase::Ways passes if node store is empty
cldellow Dec 18, 2023
0affec4
support multiple passes for ReadPhase::Relations
cldellow Dec 18, 2023
3a2c87a
fix check for first way
cldellow Dec 18, 2023
f499e34
adjust shards
cldellow Dec 18, 2023
bbf0957
Relations: fix effectiveShards > 1 check
cldellow Dec 19, 2023
4130f51
extend --materialize-geometries to LayerAsCentroid
cldellow Dec 22, 2023
d6d3f0e
add `DequeMap`, change AttributeStore to use it
cldellow Dec 23, 2023
b234123
Merge remote-tracking branch 'origin/master' into planet-on-32gb
cldellow Dec 23, 2023
f22cfdf
capture s(this)
cldellow Dec 23, 2023
efd66bb
fix warning
cldellow Dec 23, 2023
db89f8b
fix warning, really
cldellow Dec 23, 2023
60e5261
fewer shards
cldellow Dec 23, 2023
09abd3a
extract option parsing to own file
cldellow Dec 24, 2023
48305a4
use sensible defaults based on presence of --store
cldellow Dec 24, 2023
411b71e
improve test coverage
cldellow Dec 24, 2023
3d89a78
fixes
cldellow Dec 24, 2023
1edbfd6
update number of shards to 6
cldellow Dec 24, 2023
657da1a
--store uses lazy geometries; permit overriding
cldellow Dec 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,18 @@ file(GLOB tilemaker_src_files
src/mbtiles.cpp
src/mmap_allocator.cpp
src/node_stores.cpp
src/options_parser.cpp
src/osm_lua_processing.cpp
src/osm_mem_tiles.cpp
src/osm_store.cpp
src/output_object.cpp
src/pbf_blocks.cpp
src/pmtiles.cpp
src/pooled_string.cpp
src/read_pbf.cpp
src/read_shp.cpp
src/sharded_node_store.cpp
src/sharded_way_store.cpp
src/shared_data.cpp
src/shp_mem_tiles.cpp
src/sorted_node_store.cpp
Expand Down
52 changes: 49 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,18 @@ tilemaker: \
src/mbtiles.o \
src/mmap_allocator.o \
src/node_stores.o \
src/options_parser.o \
src/osm_lua_processing.o \
src/osm_mem_tiles.o \
src/osm_store.o \
src/output_object.o \
src/pbf_blocks.o \
src/pmtiles.o \
src/pooled_string.o \
src/read_pbf.o \
src/read_shp.o \
src/sharded_node_store.o \
src/sharded_way_store.o \
src/shared_data.o \
src/shp_mem_tiles.o \
src/sorted_node_store.o \
Expand All @@ -125,15 +129,57 @@ tilemaker: \
src/write_geometry.o
$(CXX) $(CXXFLAGS) -o tilemaker $^ $(INC) $(LIB) $(LDFLAGS)

test: test_sorted_way_store
test: \
test_append_vector \
test_attribute_store \
test_deque_map \
test_pooled_string \
test_sorted_node_store \
test_sorted_way_store

test_append_vector: \
src/mmap_allocator.o \
test/append_vector.test.o
$(CXX) $(CXXFLAGS) -o test.append_vector $^ $(INC) $(LIB) $(LDFLAGS) && ./test.append_vector

test_attribute_store: \
src/mmap_allocator.o \
src/attribute_store.o \
src/pooled_string.o \
test/attribute_store.test.o
$(CXX) $(CXXFLAGS) -o test.attribute_store $^ $(INC) $(LIB) $(LDFLAGS) && ./test.attribute_store

test_deque_map: \
test/deque_map.test.o
$(CXX) $(CXXFLAGS) -o test.deque_map $^ $(INC) $(LIB) $(LDFLAGS) && ./test.deque_map

test_options_parser: \
src/options_parser.o \
test/options_parser.test.o
$(CXX) $(CXXFLAGS) -o test.options_parser $^ $(INC) $(LIB) $(LDFLAGS) && ./test.options_parser

test_pooled_string: \
src/mmap_allocator.o \
src/pooled_string.o \
test/pooled_string.test.o
$(CXX) $(CXXFLAGS) -o test.pooled_string $^ $(INC) $(LIB) $(LDFLAGS) && ./test.pooled_string

test_sorted_node_store: \
src/external/streamvbyte_decode.o \
src/external/streamvbyte_encode.o \
src/external/streamvbyte_zigzag.o \
src/mmap_allocator.o \
src/sorted_node_store.o \
test/sorted_node_store.test.o
$(CXX) $(CXXFLAGS) -o test.sorted_node_store $^ $(INC) $(LIB) $(LDFLAGS) && ./test.sorted_node_store

test_sorted_way_store: \
src/external/streamvbyte_decode.o \
src/external/streamvbyte_encode.o \
src/external/streamvbyte_zigzag.o \
src/mmap_allocator.o \
src/sorted_way_store.o \
src/sorted_way_store.test.o
test/sorted_way_store.test.o
$(CXX) $(CXXFLAGS) -o test.sorted_way_store $^ $(INC) $(LIB) $(LDFLAGS) && ./test.sorted_way_store


Expand All @@ -153,6 +199,6 @@ install:
install docs/man/tilemaker.1 ${DESTDIR}${MANPREFIX}/man1/

clean:
rm -f tilemaker src/*.o src/external/*.o include/*.o include/*.pb.h
rm -f tilemaker src/*.o src/external/*.o include/*.o include/*.pb.h test/*.o

.PHONY: install
195 changes: 195 additions & 0 deletions include/append_vector.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
#ifndef _APPEND_VECTOR_H
#define _APPEND_VECTOR_H

#include "mmap_allocator.h"
#include <vector>
#include <queue>

// Tilemaker collects OutputObjects in a list that
// - spills to disk
// - only gets appended to
//
// Vector is great for linear access, but resizes cause expensive disk I/O to
// copy elements.
//
// Deque is great for growing without disk I/O, but it allocates in blocks of 512,
// which is inefficient for linear access.
//
// Instead, we author a limited vector-of-vectors class that allocates in bigger chunks,
// to get the best of both worlds.

#define APPEND_VECTOR_SIZE 8192
namespace AppendVectorNS {
template <class T>
class AppendVector {
public:
struct Iterator {
using iterator_category = std::random_access_iterator_tag;
using difference_type = std::ptrdiff_t;
using value_type = T;
using pointer = T*;
using reference = T&;

Iterator(AppendVector<T>& appendVector, uint16_t vec, uint16_t offset):
appendVector(&appendVector), vec(vec), offset(offset) {}

Iterator():
appendVector(nullptr), vec(0), offset(0) {}


bool operator<(const Iterator& other) const {
if (vec < other.vec)
return true;

if (vec > other.vec)
return false;

return offset < other.offset;
}

bool operator>=(const Iterator& other) const {
return !(*this < other);
}

Iterator operator-(int delta) const {
int64_t absolute = vec * APPEND_VECTOR_SIZE + offset;
absolute -= delta;
return Iterator(*appendVector, absolute / APPEND_VECTOR_SIZE, absolute % APPEND_VECTOR_SIZE);
}

Iterator operator+(int delta) const {
int64_t absolute = vec * APPEND_VECTOR_SIZE + offset;
absolute += delta;
return Iterator(*appendVector, absolute / APPEND_VECTOR_SIZE, absolute % APPEND_VECTOR_SIZE);
}

bool operator==(const Iterator& other) const {
return appendVector == other.appendVector && vec == other.vec && offset == other.offset;
}

bool operator!=(const Iterator& other) const {
return !(*this == other);
}

std::ptrdiff_t operator-(const Iterator& other) const {
int64_t absolute = vec * APPEND_VECTOR_SIZE + offset;
int64_t otherAbsolute = other.vec * APPEND_VECTOR_SIZE + other.offset;

return absolute - otherAbsolute;
}

reference operator*() const {
auto& vector = appendVector->vecs[vec];
auto& el = vector[offset];
return el;
}

pointer operator->() const {
auto& vector = appendVector->vecs[vec];
auto& el = vector[offset];
return &el;
}

Iterator& operator+= (int delta) {
int64_t absolute = vec * APPEND_VECTOR_SIZE + offset;
absolute += delta;

vec = absolute / APPEND_VECTOR_SIZE;
offset = absolute % APPEND_VECTOR_SIZE;
return *this;
}

Iterator& operator-= (int delta) {
int64_t absolute = vec * APPEND_VECTOR_SIZE + offset;
absolute -= delta;

vec = absolute / APPEND_VECTOR_SIZE;
offset = absolute % APPEND_VECTOR_SIZE;
return *this;
}

// Prefix increment
Iterator& operator++() {
offset++;
if (offset == APPEND_VECTOR_SIZE) {
offset = 0;
vec++;
}
return *this;
}

// Postfix increment
Iterator operator++(int) { Iterator tmp = *this; ++(*this); return tmp; }

// Prefix decrement
Iterator& operator--() {
if (offset > 0) {
offset--;
} else {
vec--;
offset = APPEND_VECTOR_SIZE - 1;
}

return *this;
}

// Postfix decrement
Iterator operator--(int) { Iterator tmp = *this; --(*this); return tmp; }

private:
mutable AppendVector<T>* appendVector;
int32_t vec, offset;
};

AppendVector():
count(0),
vecs(1) {
}

void clear() {
count = 0;
vecs.clear();
vecs.push_back(std::vector<T, mmap_allocator<T>>());
vecs.back().reserve(APPEND_VECTOR_SIZE);
}

size_t size() const {
return count;
}

T& operator [](int idx) {
auto& vec = vecs[idx / APPEND_VECTOR_SIZE];
auto& el = vec[idx % APPEND_VECTOR_SIZE];
return el;
}

Iterator begin() {
return Iterator(*this, 0, 0);
}

Iterator end() {
return Iterator(*this, vecs.size() - 1, count % APPEND_VECTOR_SIZE);
}

void push_back(const T& el) {
if (vecs.back().capacity() == 0)
vecs.back().reserve(APPEND_VECTOR_SIZE);

vecs.back().push_back(el);

if (vecs.back().size() == vecs.back().capacity()) {
vecs.push_back(std::vector<T, mmap_allocator<T>>());
vecs.back().reserve(APPEND_VECTOR_SIZE);
}

count++;
}

size_t count;
std::deque<std::vector<T, mmap_allocator<T>>> vecs;
};
}

#undef APPEND_VECTOR_SIZE

#endif
Loading
Loading