What is uncached

Uncached

Synopsis

OWFS stores recent measurements, and only updates them every 15 seconds or so, unless you ask specifically for fresh ("uncached") measurement. This makes the system appear faster, and often works well (how fast does the temperature really change?) but can be confusing.

The Problem 

You're reading temperatures and you get abrupt changes. What's happening?  

 Cached vs Uncached example

OWFS, by default, will "cache" some values, rather than rereading. You can get around this easily by reading from the "uncached" directory. 

Forcing a measurement

A new measurement will  (or new reading of device contents) will be made whenever:

  1. A reading from the "uncached" directory is requested.
  2. The old data has expired.
  3. Some obscure invalidating conditions (Requesting simultaneous conversion, writing single elements of aggregate data, ...)
Basically, if you want the latest, read from "uncached".
 

Data types

  • Volatile

    • Thing changed externally, like temperature, voltages, electrical contacts...
    • 15 second default cache timeout
  • Stable

    • Values you set (memory contents, internal flags, switch settings)
    • Writing to this value updates the cache
    • 300 second (5 minute) default timeout
  • Directory

    • List of devices connected to the 1-wire bus
    • 60 second (1 minute) default timeout
  • Presence

    • Location of a device (which of several bus)
    • 120 second (2 minute) default timeout
  • Clock

  • Static data / Statistics / Settings / Internal states

    • Generated "on-the-fly" by OWFS
    • Examples include device names, addresses, CRC8, property lists, statistics
    • Never cached -- no advantage over recalculating

Changing timeouts -- command line

~/owfs> owhttpd --help=cache
1-WIRE access programs by Paul H Alfille and others.

Cache and Timing Help

 Cache
 --cache_size n Size in bytes of max cache memory. 0 for no limit.

 Cache timing [default] (in seconds)
 --timeout_volatile [ 15] Expiration time for changing data (e.g. temperature)
 --timeout_stable [300] Expiration time for stable data (e.g. temperature limit)
 --timout_directory [ 60] Expiration of directory lists
 --timeout_presence [120] Expiration of known 1-wire device location

 Communication timing [default] (in seconds)
 --timeout_serial [ 5] Timeout for serial port read
 --timeout_usb [ 5] Timeout for USB transaction
 --timeout_network [ 1] Timeout for each network transaction
 --timeout_server [ 10] Timeout for first server connection
 --timeout_ftp [900] Timeout for FTP session

Copyright 2003 GPLv2. See http://www.owfs.org for support, downloads
 

Changing timeouts -- within the program

The timeouts are read/writable values found under /settings/timeout/[volatile|stable|directory|presence]

For example, using owhttpd:

settings/timeout

Memory restrictions

  • Can caching be turned off?
    Yes, at compile time (DISABLE_CACHE) or by setting the timeout to 0 at runtime.
  • Can caching memory be bounded?
    Yes, with the cache_size command line argument
  • How much memory does each entry use?
    Not much. Depends on computer architecture (32 bit vs 64 bit) but about 32 bytes for the header and then data element size.
  • What happens when memory is exhuasted?
    In theory OWFS will degrade gracefully since caching is optional. In practice, other memory allocations will also start failing, which may be awkward.
  • Is there a natural bound to memory usage for the cache?
    Probably, based on the physical limits of the 1-wire bus. Perhaps 2K bytes/second ? 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 120 122 123 124 125 126 128 137 138 139 140 141 142 143 144 145 146 147 161 164 173 175 176 177 178 179 180 182 193 194 197 216 217 302 3rd-party-devices 4-channel-hub 63 64 66 67 68 69 71 72 73 74 75 76 77 78 80 81 82 83 84 85 86 87 88 89 8-channel-i-o 90 91 92 93 94 95 96 97 98 99 address-discovery admin advanced advanced-i2c aliases alias-improved appliances aquarium-automation----rob-conway asus-wireless----wim-heirman avahi-discovery bae910 barometer beaglebone-black binary-sizes bonjour-library bonjour-zeroconf building-under-ubuntu bus-masters cache cache-flip cache-objects cache-structure car-battery-monitoring----rohbags cgi-bin change-log changelog.html clients-window com-ds9097-passive command-line configuration configuration-file custom-hardware----william-robison datanab-humidity-sensor debian debug debugging detail detail-windows detail-windows-2 directory-locking directory-messages display distributions divide-and-conqueror download ds1427 ds1821 ds1821-thermostat-circuit----doug-collinge ds1822 ds1825 ds18b20 ds18s20 ds1904 ds1920 ds1921 ds1963l ds1963s ds1977 ds1982 ds1982-2 ds1985 ds1985-2 ds1986 ds1986u ds1990a ds1991 ds1992 ds1993 ds1994 ds1995 ds1996 ds2401 ds2404 ds2404s ds2405 ds2406 ds2407 ds2408 ds2409 ds2409-microhub ds2411 ds2413 ds2415 ds2417 ds2423 ds2430a ds2431 ds2433 ds2436 ds2437 ds2438 ds2450 ds2502 ds2502-unw ds2505 ds2505-2 ds2506 ds2506-unw ds2720 ds2740 ds2751 ds2755 ds2756 ds2760 ds2761 ds2762 ds2770 ds2780 ds2781 ds2788 ds2804 ds2890 ds28ea00 ds28ec20 eclo eds0064 eds0065---temperature-humidity eds0066 eds0067---temperature-light eds0068---temperature-humidity-pressure-light eds0070 eds0071---rtd-temperature eds00xx eds-enviromental-sensors eeef enet-configuration enet-firmware error-codes error_level error-management error-numbers error_print etherweather examples external-sensor-design fake-adapter family-code-list family-code-lookup fan-and-battery-control----majek-wodzinski faq favicon.ico fli4l foreground fox-board foxboard-g20 ftp-browsing full---libow fuse garden gentoo gentoo-scripts git-access gitinspector.html greenhouse-control ha7e ha7net hardware help help-2 help-device home home-monitoring-how-to----silvano-gai home-trailer----brian-fahrlander hotplug hubs humidity hydroelectric-plant i2c-ds2482-100 i2c-ds2482-800 i2c-parallel-port-design images index.html index.php index.php? initial-nslu2-preparation install internal-help-cache internal-help-job internal-help-program internal-help-temperature javascript-raphaell-js Language-modules lcd lcd-2 lcd-temperature-display license light-sensor linkhub-e linkusb locator locks-and-unlocks logo-poll loop-suppression macintosh maintainers main-window mam001 man-pages-ds18xx man-pages-ds19xx man-pages-ds24xx man-pages-ds25xx man-pages-ds27xx man-pages-misc-devices man-pages-programs master-and-slaves mcm001 message-statistics modules moisture monitor-a-wine-cellar mrs001 ms-windows netbsd nslu2 nslu2-german object-read-process object-write-process office-monitoring----wim-heirman omap one-wire-on-fire owcapi owcapi-2 owfs owfs-install-step owfs-websites owftpd owhttpd owmon owmon-2 owmon-bus-list owmon-main-window OWNet ownet-2 ownet-php ownet-pm ownet-py owperl owphp owserver ow-server-enet owserver-flag-word owserver-message-types owserver_protocol owserver-protocol owshell owtap owtap-2 owtcl performance permissions persistence-windows persistent-connections persistent-connections----owlib-client porting postgres-and-python-by-jerry-scharf Programs pyzine-by-peter-kropf-owpython quickstart-guide quirks-and-problems raspberry-pi read-and-write-object reef-tank remote-cache robots.txt rtd-sensor search seather-station setup setup-2 slackware slave-code slave-support snmp so2-sencor software solar-heating-control----christian-schumann-and-christian-magnusson source-code-availability standard-devices startup-avahi startup-ds9097u startup-fake startup-ha5 startup-ha7net startup-link-ascii-mode startup-link-emulate-mode startup-linkusb startup-mock startup-owserver startup-ow-server-enet startup-passive-9097 startup-sequence startup-tester startup-usb-ds9490r startup-usb-scan statcvs status-window struct-owq_wire_query-assumptions structure-directory stylesheetmediatypeprint.css stylesheetmediatypescreen.css stylesheet.php?templateid=20 stylesheet.php?templateid=20&mediatype=print stylesheet.php?templateid=20&mediatype=screen stylesheettemplateid.css survey switches tai603b tcp-messages temperature-compensation temperature-measurements tester-adapter testing-without-hardware thermocouples to-do t.sh tutorial-links type-b type-e type-j type-k type-n type-r type-s type-t ubuntu ubuntu-setup udev udev-and-usb uploads usb-ds9490r usb-eclo usb-mp00200 usb-usb9097 uvi vendors vibration-sensor visual-basic-control voltage voltage-measurement w1-project water-tank-monitor----mr-packethead weather----owfsws what-is-1-wire what-is-1-wire-good-for what-is-uncached what-is-uncached.html windows-usb wireless-router wiring-standards wl-hdd wrt-router-mods----p4trykx ws603-weather-instrument 3600 second timeout ? 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 120 122 123 124 125 126 128 137 138 139 140 141 142 143 144 145 146 147 161 164 173 175 176 177 178 179 180 182 193 194 197 216 217 302 3rd-party-devices 4-channel-hub 63 64 66 67 68 69 71 72 73 74 75 76 77 78 80 81 82 83 84 85 86 87 88 89 8-channel-i-o 90 91 92 93 94 95 96 97 98 99 address-discovery admin advanced advanced-i2c aliases alias-improved appliances aquarium-automation----rob-conway asus-wireless----wim-heirman avahi-discovery bae910 barometer beaglebone-black binary-sizes bonjour-library bonjour-zeroconf building-under-ubuntu bus-masters cache cache-flip cache-objects cache-structure car-battery-monitoring----rohbags cgi-bin change-log changelog.html clients-window com-ds9097-passive command-line configuration configuration-file custom-hardware----william-robison datanab-humidity-sensor debian debug debugging detail detail-windows detail-windows-2 directory-locking directory-messages display distributions divide-and-conqueror download ds1427 ds1821 ds1821-thermostat-circuit----doug-collinge ds1822 ds1825 ds18b20 ds18s20 ds1904 ds1920 ds1921 ds1963l ds1963s ds1977 ds1982 ds1982-2 ds1985 ds1985-2 ds1986 ds1986u ds1990a ds1991 ds1992 ds1993 ds1994 ds1995 ds1996 ds2401 ds2404 ds2404s ds2405 ds2406 ds2407 ds2408 ds2409 ds2409-microhub ds2411 ds2413 ds2415 ds2417 ds2423 ds2430a ds2431 ds2433 ds2436 ds2437 ds2438 ds2450 ds2502 ds2502-unw ds2505 ds2505-2 ds2506 ds2506-unw ds2720 ds2740 ds2751 ds2755 ds2756 ds2760 ds2761 ds2762 ds2770 ds2780 ds2781 ds2788 ds2804 ds2890 ds28ea00 ds28ec20 eclo eds0064 eds0065---temperature-humidity eds0066 eds0067---temperature-light eds0068---temperature-humidity-pressure-light eds0070 eds0071---rtd-temperature eds00xx eds-enviromental-sensors eeef enet-configuration enet-firmware error-codes error_level error-management error-numbers error_print etherweather examples external-sensor-design fake-adapter family-code-list family-code-lookup fan-and-battery-control----majek-wodzinski faq favicon.ico fli4l foreground fox-board foxboard-g20 ftp-browsing full---libow fuse garden gentoo gentoo-scripts git-access gitinspector.html greenhouse-control ha7e ha7net hardware help help-2 help-device home home-monitoring-how-to----silvano-gai home-trailer----brian-fahrlander hotplug hubs humidity hydroelectric-plant i2c-ds2482-100 i2c-ds2482-800 i2c-parallel-port-design images index.html index.php index.php? initial-nslu2-preparation install internal-help-cache internal-help-job internal-help-program internal-help-temperature javascript-raphaell-js Language-modules lcd lcd-2 lcd-temperature-display license light-sensor linkhub-e linkusb locator locks-and-unlocks logo-poll loop-suppression macintosh maintainers main-window mam001 man-pages-ds18xx man-pages-ds19xx man-pages-ds24xx man-pages-ds25xx man-pages-ds27xx man-pages-misc-devices man-pages-programs master-and-slaves mcm001 message-statistics modules moisture monitor-a-wine-cellar mrs001 ms-windows netbsd nslu2 nslu2-german object-read-process object-write-process office-monitoring----wim-heirman omap one-wire-on-fire owcapi owcapi-2 owfs owfs-install-step owfs-websites owftpd owhttpd owmon owmon-2 owmon-bus-list owmon-main-window OWNet ownet-2 ownet-php ownet-pm ownet-py owperl owphp owserver ow-server-enet owserver-flag-word owserver-message-types owserver_protocol owserver-protocol owshell owtap owtap-2 owtcl performance permissions persistence-windows persistent-connections persistent-connections----owlib-client porting postgres-and-python-by-jerry-scharf Programs pyzine-by-peter-kropf-owpython quickstart-guide quirks-and-problems raspberry-pi read-and-write-object reef-tank remote-cache robots.txt rtd-sensor search seather-station setup setup-2 slackware slave-code slave-support snmp so2-sencor software solar-heating-control----christian-schumann-and-christian-magnusson source-code-availability standard-devices startup-avahi startup-ds9097u startup-fake startup-ha5 startup-ha7net startup-link-ascii-mode startup-link-emulate-mode startup-linkusb startup-mock startup-owserver startup-ow-server-enet startup-passive-9097 startup-sequence startup-tester startup-usb-ds9490r startup-usb-scan statcvs status-window struct-owq_wire_query-assumptions structure-directory stylesheetmediatypeprint.css stylesheetmediatypescreen.css stylesheet.php?templateid=20 stylesheet.php?templateid=20&mediatype=print stylesheet.php?templateid=20&mediatype=screen stylesheettemplateid.css survey switches tai603b tcp-messages temperature-compensation temperature-measurements tester-adapter testing-without-hardware thermocouples to-do t.sh tutorial-links type-b type-e type-j type-k type-n type-r type-s type-t ubuntu ubuntu-setup udev udev-and-usb uploads usb-ds9490r usb-eclo usb-mp00200 usb-usb9097 uvi vendors vibration-sensor visual-basic-control voltage voltage-measurement w1-project water-tank-monitor----mr-packethead weather----owfsws what-is-1-wire what-is-1-wire-good-for what-is-uncached what-is-uncached.html windows-usb wireless-router wiring-standards wl-hdd wrt-router-mods----p4trykx ws603-weather-instrument number of buses. This assumes 1000s of physical 1-wire devices. Even so, the memory size is trivial for modern machines.

Tests on Caching -- single process

Caching single process

Here is the time taken to read a bank of 10 DS18S20 temperature sensors in succession (several times).

After the first 10 readings, the uncached process only rarely needs to delay -- only when the time runs out. Uncached takes far longer.

What does this mean?

  1. The DS18S20 is particularly slow at full resolution (~1second/sample)
  2.  Caching essentially "decouples" your program from the need to worry about sampling time. You can read the temperature whenever you want, and have a delay only when it's time for a new reading.

Tests on Caching -- two processes

Let's add two concurrent processes, each trying the same task as before -- reading 10 temperature sensors in a loop.

Caching -- 2 processes

  1. Uncached contention is at least additive in time. So the elapsed time will double for each process.
  2. Cached dual processes is very fast, but slightly twice the elapsed time of the single. Either this is caused purely by bus locking and network traffic, or the slight extra work pushed us over the volatile time threshold. 

Advanced topics

The actual design of the cache is quite clever, and well tuned. Briefly, data is keyed by device and "property" in a red-black tree. See Cache design for implementation details. Access is fast (binary search in main memory) and the table is regularly purged of expired data.