@@ -14,7 +14,7 @@ module PlaceOS::Source
1414 STATUS_CHANNEL_PATTERN = " status/#{ Model ::Module .table_name} -*"
1515 MAX_CONTAINER_SIZE = 40_000
1616 BATCH_SIZE = 100
17- PROCESSING_INTERVAL = 100 .milliseconds
17+ PROCESSING_INTERVAL = 40 .milliseconds
1818 CONTAINER_WARNING_THRESHOLD = MAX_CONTAINER_SIZE * 0.8
1919
2020 private getter! redis : Redis
@@ -80,7 +80,9 @@ module PlaceOS::Source
8080
8181 # process
8282 break if modules.empty?
83- yield modules
83+ modules.each do |mod |
84+ yield mod
85+ end
8486 break if modules.size < batch_size
8587
8688 last_created_at = modules.last.created_at
@@ -92,26 +94,23 @@ module PlaceOS::Source
9294 mods_mapped = 0 _u64
9395 status_updated = 0 _u64
9496 pattern = " initial_sync"
95- paginate_modules do |modules |
96- modules.each do |mod |
97- next unless mod
98- mods_mapped += 1 _u64
99- module_id = mod.id.to_s
100- store = PlaceOS ::Driver ::RedisStorage .new(module_id)
101- store.each do |key , value |
102- status_updated += 1 _u64
103- add_event({source: :db , mod_id: module_id, status: key}, {pattern: pattern, payload: value, timestamp: Time .utc})
104- end
97+ paginate_modules do |mod |
98+ mods_mapped += 1 _u64
99+ module_id = mod.id.to_s
100+ store = PlaceOS ::Driver ::RedisStorage .new(module_id)
101+ store.each do |key , value |
102+ status_updated += 1 _u64
103+ add_event({source: :db , mod_id: module_id, status: key}, {pattern: pattern, payload: value, timestamp: Time .utc})
104+ end
105105
106- # Backpressure if event container is growing too fast
107- if event_container.size >= MAX_CONTAINER_SIZE / 2
108- until event_container.size < MAX_CONTAINER_SIZE / 4
109- sleep 10 .milliseconds
110- end
106+ # Backpressure if event container is growing too fast
107+ if event_container.size > MAX_CONTAINER_SIZE // 2
108+ until event_container.size < MAX_CONTAINER_SIZE // 4
109+ sleep 10 .milliseconds
111110 end
112- rescue error
113- Log .warn(exception: error) { " error syncing #{ mod.try(& .id) } " }
114111 end
112+ rescue error
113+ Log .warn(exception: error) { " error syncing #{ mod.try(& .id) } " }
115114 end
116115 Log .info { {
117116 message: " initial status sync complete" ,
@@ -131,26 +130,23 @@ module PlaceOS::Source
131130 status_updated = 0 _u64
132131 pattern = " broker_resync"
133132
134- paginate_modules do |modules |
135- modules.each do |mod |
136- next unless mod
137- mods_mapped += 1 _u64
138- module_id = mod.id.to_s
139- store = PlaceOS ::Driver ::RedisStorage .new(module_id)
140- store.each do |key , value |
141- status_updated += 1 _u64
142- add_event({source: :db , mod_id: module_id, status: key}, {pattern: pattern, payload: value, timestamp: Time .utc})
143- end
133+ paginate_modules do |mod |
134+ mods_mapped += 1 _u64
135+ module_id = mod.id.to_s
136+ store = PlaceOS ::Driver ::RedisStorage .new(module_id)
137+ store.each do |key , value |
138+ status_updated += 1 _u64
139+ add_event({source: :db , mod_id: module_id, status: key}, {pattern: pattern, payload: value, timestamp: Time .utc})
140+ end
144141
145- # Backpressure if event container is growing too fast
146- if event_container.size >= MAX_CONTAINER_SIZE / 2
147- until event_container.size < MAX_CONTAINER_SIZE / 4
148- sleep 10 .milliseconds
149- end
142+ # Backpressure if event container is growing too fast
143+ if event_container.size >= MAX_CONTAINER_SIZE // 2
144+ until event_container.size < MAX_CONTAINER_SIZE // 4
145+ sleep 10 .milliseconds
150146 end
151- rescue error
152- Log .warn(exception: error) { " error resyncing #{ mod.try(& .id) } " }
153147 end
148+ rescue error
149+ Log .warn(exception: error) { " error resyncing #{ mod.try(& .id) } " }
154150 end
155151
156152 Log .info { {
@@ -191,6 +187,18 @@ module PlaceOS::Source
191187 else
192188 process_batch(batch)
193189 Fiber .yield
190+
191+ # This outputs how many writes have occured for each publisher
192+ # stats = String.build do |io|
193+ # io << "\n\n\nNEXT BATCH:\n"
194+ # publisher_managers.each do |manager|
195+ # manager.stats.each do |name, count|
196+ # io << " * #{name} => #{count}"
197+ # end
198+ # end
199+ # io << "\n\n"
200+ # end
201+ # puts stats
194202 end
195203 rescue error
196204 Log .error(exception: error) { " error processing events" }
0 commit comments