Uploader speedup (#2214)

* use caching for getxattr

* fix some git issues

* Scheduled network checks

* attempt optimization

* Delete speed_test.py

* Style fixes

* Fix styling

* fix spaces

* fix spaces

* fix naming

* Update uploader.py

* Update mark_all_uploaded.py

* Add file to release

* Update selfdrive/loggerd/tools/mark_all_uploaded.py

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
pull/2218/head
grekiki 5 years ago committed by GitHub
parent afdb4ce61e
commit cf46de13d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      release/files_common
  2. 9
      selfdrive/loggerd/tools/mark_all_uploaded.py
  3. 11
      selfdrive/loggerd/uploader.py
  4. 13
      selfdrive/loggerd/xattr_cache.py

@ -315,6 +315,7 @@ selfdrive/loggerd/__init__.py
selfdrive/loggerd/config.py selfdrive/loggerd/config.py
selfdrive/loggerd/uploader.py selfdrive/loggerd/uploader.py
selfdrive/loggerd/deleter.py selfdrive/loggerd/deleter.py
selfdrive/loggerd/xattr_cache.py
selfdrive/sensord/SConscript selfdrive/sensord/SConscript
selfdrive/sensord/gpsd.cc selfdrive/sensord/gpsd.cc

@ -0,0 +1,9 @@
import os
from common.xattr import setxattr
from selfdrive.loggerd.uploader import UPLOAD_ATTR_NAME, UPLOAD_ATTR_VALUE
from selfdrive.loggerd.config import ROOT
for folder in os.walk(ROOT):
for file1 in folder[2]:
full_path = os.path.join(folder[0], file1)
setxattr(full_path, UPLOAD_ATTR_NAME, UPLOAD_ATTR_VALUE)

@ -16,7 +16,7 @@ from cereal import log
from common.hardware import HARDWARE from common.hardware import HARDWARE
from common.api import Api from common.api import Api
from common.params import Params from common.params import Params
from common.xattr import getxattr, setxattr from selfdrive.loggerd.xattr_cache import getxattr, setxattr
from selfdrive.loggerd.config import ROOT from selfdrive.loggerd.config import ROOT
from selfdrive.swaglog import cloudlog from selfdrive.swaglog import cloudlog
@ -26,6 +26,7 @@ UPLOAD_ATTR_VALUE = b'1'
fake_upload = os.getenv("FAKEUPLOAD") is not None fake_upload = os.getenv("FAKEUPLOAD") is not None
def raise_on_thread(t, exctype): def raise_on_thread(t, exctype):
'''Raises an exception in the threads with id tid''' '''Raises an exception in the threads with id tid'''
for ctid, tobj in threading._active.items(): for ctid, tobj in threading._active.items():
@ -127,11 +128,11 @@ class Uploader():
is_uploaded = True # deleter could have deleted is_uploaded = True # deleter could have deleted
if is_uploaded: if is_uploaded:
continue continue
yield (name, key, fn) yield (name, key, fn)
def next_file_to_upload(self, with_raw): def next_file_to_upload(self, with_raw):
upload_files = list(self.gen_upload_files()) upload_files = list(self.gen_upload_files())
# try to upload qlog files first # try to upload qlog files first
for name, key, fn in upload_files: for name, key, fn in upload_files:
if name in self.immediate_priority: if name in self.immediate_priority:
@ -236,14 +237,19 @@ def uploader_fn(exit_event):
uploader = Uploader(dongle_id, ROOT) uploader = Uploader(dongle_id, ROOT)
backoff = 0.1 backoff = 0.1
counter = 0
should_upload = False
while not exit_event.is_set(): while not exit_event.is_set():
offroad = params.get("IsOffroad") == b'1' offroad = params.get("IsOffroad") == b'1'
allow_raw_upload = (params.get("IsUploadRawEnabled") != b"0") and offroad allow_raw_upload = (params.get("IsUploadRawEnabled") != b"0") and offroad
check_network = (counter % 12 == 0 if offroad else True)
if check_network:
on_hotspot = is_on_hotspot() on_hotspot = is_on_hotspot()
on_wifi = is_on_wifi() on_wifi = is_on_wifi()
should_upload = on_wifi and not on_hotspot should_upload = on_wifi and not on_hotspot
d = uploader.next_file_to_upload(with_raw=allow_raw_upload and should_upload) d = uploader.next_file_to_upload(with_raw=allow_raw_upload and should_upload)
counter += 1
if d is None: # Nothing to upload if d is None: # Nothing to upload
time.sleep(60 if offroad else 5) time.sleep(60 if offroad else 5)
continue continue
@ -264,5 +270,6 @@ def uploader_fn(exit_event):
def main(): def main():
uploader_fn(threading.Event()) uploader_fn(threading.Event())
if __name__ == "__main__": if __name__ == "__main__":
main() main()

@ -0,0 +1,13 @@
from common.xattr import getxattr as getattr1
from common.xattr import setxattr as setattr1
cached_attributes = {}
def getxattr(path, attr_name):
if (path, attr_name) not in cached_attributes:
response = getattr1(path, attr_name)
cached_attributes[(path, attr_name)] = response
return cached_attributes[(path, attr_name)]
def setxattr(path, attr_name, attr_value):
cached_attributes.pop((path, attr_name), None)
return setattr1(path, attr_name, attr_value)
Loading…
Cancel
Save