out of memory: select * from <series> where time > now() - 1m in over million rows
Hi,
We have a little instance running up in a 2-core / 8gb RAM machine here. We have a series with over a million writes, with constant writes (80k/hour ish).
Influx is dying of OOM all the time when querying with a minute long search, not sure what we're doing wrong.
Requests are being written with the write endpoint and the mem usage during writes is constantly in 3-4GB range. We are writing 8 tags and 2 fields and we're using tsm1 engine, using nightly, config file is as follows:
### Welcome to the InfluxDB configuration file.
# Once every 24 hours InfluxDB will report anonymous data to m.influxdb.com
# The data includes raft id (random 8 bytes), os, arch, version, and metadata.
# We don't track ip addresses of servers reporting. This is only used
# to track the number of instances running and the versions, which
# is very helpful for us.
# Change this option to true to disable reporting.
reporting-disabled = false
###
### [meta]
###
### Controls the parameters for the Raft consensus group that stores metadata
### about the InfluxDB cluster.
###
[meta]
dir = "/var/lib/influxdb/meta"
hostname = "localhost"
bind-address = ":8088"
retention-autocreate = true
election-timeout = "1s"
heartbeat-timeout = "1s"
leader-lease-timeout = "500ms"
commit-timeout = "50ms"
cluster-tracing = false
# If enabled, when a Raft cluster loses a peer due to a `DROP SERVER` command,
# the leader will automatically ask a non-raft peer node to promote to a raft
# peer. This only happens if there is a non-raft peer node available to promote.
# This setting only affects the local node, so to ensure if operates correctly, be sure to set
# it in the config of every node.
raft-promotion-enabled = true
###
### [data]
###
### Controls where the actual shard data for InfluxDB lives and how it is
### flushed from the WAL. "dir" may need to be changed to a suitable place
### for your system, but the WAL settings are an advanced configuration. The
### defaults should work for most systems.
###
[data]
dir = "/var/lib/influxdb/data"
# Controls the storage engine used for new shards. Engines available are b1,
# bz1, and tsm1. b1 was the original default engine from 0.9.0 to 0.9.2. bz1
# has been the default engine since 0.9.3. tsm1 was introduced in 0.9.5 and is
# currently EXPERIMENTAL. Consequently, data written into the tsm1 engine may
# need to be wiped between upgrades.
engine ="tsm1"
# The following WAL settings are for the b1 storage engine used in 0.9.2. They won't
# apply to any new shards created after upgrading to a version > 0.9.3.
max-wal-size = 104857600 # Maximum size the WAL can reach before a flush. Defaults to 100MB.
wal-flush-interval = "10m" # Maximum time data can sit in WAL before a flush.
wal-partition-flush-delay = "2s" # The delay time between each WAL partition being flushed.
# These are the WAL settings for the storage engine >= 0.9.3
wal-dir = "/var/lib/influxdb/wal"
wal-logging-enabled = true
data-logging-enabled = true
# When a series in the WAL in-memory cache reaches this size in bytes it is marked as ready to
# flush to the index
# wal-ready-series-size = 25600
# Flush and compact a partition once this ratio of series are over the ready size
# wal-compaction-threshold = 0.6
# Force a flush and compaction if any series in a partition gets above this size in bytes
# wal-max-series-size = 2097152
# Force a flush of all series and full compaction if there have been no writes in this
# amount of time. This is useful for ensuring that shards that are cold for writes don't
# keep a bunch of data cached in memory and in the WAL.
wal-flush-cold-interval = "10m"
# Force a partition to flush its largest series if it reaches this approximate size in
# bytes. Remember there are 5 partitions so you'll need at least 5x this amount of memory.
# The more memory you have, the bigger this can be.
wal-partition-size-threshold = 20971520
# Whether queries should be logged before execution. Very useful for troubleshooting, but will
# log any sensitive data contained within a query.
# query-log-enabled = true
# Settings for the TSM engine
# CacheMaxMemorySize is the maximum size a shard's cache can
# reach before it starts rejecting writes.
cache-max-memory-size = 524288000
# CacheSnapshotMemorySize is the size at which the engine will
# snapshot the cache and write it to a TSM file, freeing up memory
# cache-snapshot-memory-size = 26214400
# CacheSnapshotWriteColdDuration is the length of time at
# which the engine will snapshot the cache and write it to
# a new TSM file if the shard hasn't received writes or deletes
# cache-snapshot-write-cold-duration = "1h"
# MinCompactionFileCount is the minimum number of TSM files
# that need to exist before a compaction cycle will run
# compact-min-file-count = 3
# CompactFullWriteColdDuration is the duration at which the engine
# will compact all TSM files in a shard if it hasn't received a
# write or delete
# compact-full-write-cold-duration = "24h"
# MaxPointsPerBlock is the maximum number of points in an encoded
# block in a TSM file. Larger numbers may yield better compression
# but could incur a performance peanalty when querying
# max-points-per-block = 1000
###
### [hinted-handoff]
###
### Controls the hinted handoff feature, which allows nodes to temporarily
### store queued data when one node of a cluster is down for a short period
### of time.
###
[hinted-handoff]
enabled = true
dir = "/var/lib/influxdb/hh"
max-size = 1073741824
max-age = "168h"
retry-rate-limit = 0
# Hinted handoff will start retrying writes to down nodes at a rate of once per second.
# If any error occurs, it will backoff in an exponential manner, until the interval
# reaches retry-max-interval. Once writes to all nodes are successfully completed the
# interval will reset to retry-interval.
retry-interval = "1s"
retry-max-interval = "1m"
# Interval between running checks for data that should be purged. Data is purged from
# hinted-handoff queues for two reasons. 1) The data is older than the max age, or
#2) the target node has been dropped from the cluster. Data is never dropped until
# it has reached max-age however, for a dropped node or not.
purge-interval = "1h"
###
### [cluster]
###
### Controls non-Raft cluster behavior, which generally includes how data is
### shared across shards.
###
[cluster]
shard-writer-timeout = "5s" # The time within which a remote shard must respond to a write request.
write-timeout = "10s" # The time within which a write request must complete on the cluster.
###
### [retention]
###
### Controls the enforcement of retention policies for evicting old data.
###
[retention]
enabled = true
check-interval = "30m"
###
### [shard-precreation]
###
### Controls the precreation of shards, so they are available before data arrives.
### Only shards that, after creation, will have both a start- and end-time in the
### future, will ever be created. Shards are never precreated that would be wholly
### or partially in the past.
[shard-precreation]
enabled = true
check-interval = "10m"
advance-period = "30m"
###
### Controls the system self-monitoring, statistics and diagnostics.
###
### The internal database for monitoring data is created automatically if
### if it does not already exist. The target retention within this database
### is called 'monitor' and is also created with a retention period of 7 days
### and a replication factor of 1, if it does not exist. In all cases the
### this retention policy is configured as the default for the database.
[monitor]
store-enabled = true # Whether to record statistics internally.
store-database = "_internal" # The destination database for recorded statistics
store-interval = "10s" # The interval at which to record statistics
###
### [admin]
###
### Controls the availability of the built-in, web-based admin interface. If HTTPS is
### enabled for the admin interface, HTTPS must also be enabled on the [http] service.
###
[admin]
enabled = true
bind-address = ":8083"
https-enabled = false
https-certificate = "/etc/ssl/influxdb.pem"
###
### [http]
###
### Controls how the HTTP endpoints are configured. These are the primary
### mechanism for getting data into and out of InfluxDB.
###
[http]
enabled = true
bind-address = ":8086"
auth-enabled = false
log-enabled = true
write-tracing = false
pprof-enabled = false
https-enabled = false
https-certificate = "/etc/ssl/influxdb.pem"
###
### [[graphite]]
###
### Controls one or many listeners for Graphite data.
###
[[graphite]]
enabled = false
# database = "graphite"
# bind-address = ":2003"
# protocol = "tcp"
# consistency-level = "one"
# name-separator = "."
# These next lines control how batching works. You should have this enabled
# otherwise you could get dropped metrics or poor performance. Batching
# will buffer points in memory if you have many coming in.
# batch-size = 1000 # will flush if this many points get buffered
# batch-pending = 5 # number of batches that may be pending in memory
# batch-timeout = "1s" # will flush at least this often even if we haven't hit buffer limit
# udp-read-buffer = 0 # UDP Read buffer size, 0 means OS default. UDP listener will fail if set above OS max.
## "name-schema" configures tag names for parsing the metric name from graphite protocol;
## separated by `name-separator`.
## The "measurement" tag is special and the corresponding field will become
## the name of the metric.
## e.g. "type.host.measurement.device" will parse "server.localhost.cpu.cpu0" as
## {
## measurement: "cpu",
## tags: {
## "type": "server",
## "host": "localhost,
## "device": "cpu0"
## }
## }
# name-schema = "type.host.measurement.device"
## If set to true, when the input metric name has more fields than `name-schema` specified,
## the extra fields will be ignored.
## Otherwise an error will be logged and the metric rejected.
# ignore-unnamed = true
###
### [collectd]
###
### Controls the listener for collectd data.
###
[collectd]
enabled = false
# bind-address = ""
# database = ""
# typesdb = ""
# These next lines control how batching works. You should have this enabled
# otherwise you could get dropped metrics or poor performance. Batching
# will buffer points in memory if you have many coming in.
# batch-size = 1000 # will flush if this many points get buffered
# batch-pending = 5 # number of batches that may be pending in memory
# batch-timeout = "1s" # will flush at least this often even if we haven't hit buffer limit
# read-buffer = 0 # UDP Read buffer size, 0 means OS default. UDP listener will fail if set above OS max.
###
### [opentsdb]
###
### Controls the listener for OpenTSDB data.
###
[opentsdb]
enabled = false
# bind-address = ":4242"
# database = "opentsdb"
# retention-policy = ""
# consistency-level = "one"
# tls-enabled = false
# certificate= ""
# log-point-errors = true # Log an error for every malformed point.
# These next lines control how batching works. You should have this enabled
# otherwise you could get dropped metrics or poor performance. Only points
# metrics received over the telnet protocol undergo batching.
# batch-size = 1000 # will flush if this many points get buffered
# batch-pending = 5 # number of batches that may be pending in memory
# batch-timeout = "1s" # will flush at least this often even if we haven't hit buffer limit
###
### [[udp]]
###
### Controls the listeners for InfluxDB line protocol data via UDP.
###
[[udp]]
enabled = false
# bind-address = ""
# database = "udp"
# retention-policy = ""
# These next lines control how batching works. You should have this enabled
# otherwise you could get dropped metrics or poor performance. Batching
# will buffer points in memory if you have many coming in.
# batch-size = 1000 # will flush if this many points get buffered
# batch-pending = 5 # number of batches that may be pending in memory
# batch-timeout = "1s" # will flush at least this often even if we haven't hit buffer limit
# read-buffer = 0 # UDP Read buffer size, 0 means OS default. UDP listener will fail if set above OS max.
# set the expected UDP payload size; lower values tend to yield better performance, default is max UDP size 65536
# udp-payload-size = 65536
###
### [continuous_queries]
###
### Controls how continuous queries are run within InfluxDB.
###
[continuous_queries]
log-enabled = true
enabled = true
# run-interval = "1s" # interval for how often continuous queries will be checked if they need to run
this seems to be a running theme, looking the last 3 weeks to tickets. Is there any max memory set per query ?
@brenol the total number of points in the series isn't relevant to the query performance, only the number of points matching the selection criteria. There's no reason that a query sampling ~25 points should OOM.
What do the logs show? Does the query still OOM if you restrict it to the prior 30 seconds? 15 seconds? Can you share the actual query?
@mhiller there is no current way to limit RAM or kill running queries.
@beckettsean
I'm doing the following select:
> select count(elapsed) from send where time > now() - 10s
ERR: Get http://localhost:8086/query?db=sm&epoch=ns&q=select+count%28elapsed%29+from+send+where+time+%3E+now%28%29+-+10s: EOF
/run.sh: line 143: 10 Killed exec influxd -config=${CONFIG_FILE}
It also got killed by this one:
> select count(elapsed) from send where time > now() - 1u
ERR: Get http://localhost:8086/query?db=sm&epoch=ns&q=select+count%28elapsed%29+from+send+where+time+%3E+now%28%29+-+1u: EOF
Thanks!
@brenol is the machine almost completely out of RAM before the queries are run? What does the resident set size look like before and during the query? I see no reason why that query should OOM the system.
Does it always OOM for the same query? Are there queries that never OOM?
@beckettsean nope, it's usually in the 3-4 GB area when we start running the query. Please note that it has 8GB RAM.
It always OOM for all queries in that database. Querying in another one has no issues at all (however, that one barely has 10000 rows).
If there's anything else I can search for you (in logs), please tell me. I'm running it in the InfluxCli and it's just outputting err and then I see that the system killed the process.
Thanks!
Please include the logs when it OOMs. I have never heard of a system where all queries on a particular database OOM, but it sounds like corruption, possibly. I can think of no sensible reason why a query sampling a few points would need 3-4GB of RAM.
How are the points written to the database? Is that a different method than the points written to the database that doesn't OOM?
I have seen a few times that it did panic, however, it was a simple runtime error: out of memory. Most of the time there isn't any time for a panic to show up, though, as the system kills influxdb.
We are writing in the following way (concurrently, obviously):
curl -X POST "http://localhost:8086/write?db=sm&u=user&password=pass123" -d "send,number=10902901,profile=03.12,ttl=3,la=212,parts=2,status=0 elapsed=10.0029,value=1"
The database that doesn't OOM writes using the Go client, and writes in batches (different data though).
If you aren't batching the writes to the sm database, perhaps it's the HTTP stack that's leading to OOM issues. 20-25 HTTP connections per second is non-trivial, and then the query introduces more. Is it possible to batch the writes and see if that mitigates the behavior in any way?
I'm not certain that this is the issue, and I have no mechanism to propose, but un-batched HTTP writes are rarely a good idea beyond trivial testing.
@beckettsean
We have also tried with disabled HTTP writes, and database keeps OOMing upon query. I'll try to build a test script to see if the problem can be reproduced.
Thanks!
I am experiencing the same or similar issue. I am running a single cluster with 8 Gb of ram. 3-4 Gb of ram is available at the time of query. I am running on a Centos6 AWS node.
if i run a basic but large query I don't get any problems select * from sample / around 6000 results with 20 columns
but if i run a small but more complex it fails intermittently SELECT mean("ssid_scan_time") FROM "sample" WHERE "device_id" = 'hgf_hfx_17' AND time > 1453352400s and time < now() GROUP BY time(1m) fill(null) / roughly 100 results with 2 columns
@benbjohnson some issues with complex but small returns for the old query engine, something to consider with the refactor.
@beckettsean the new QE should have a low, fixed memory usage per series. We'll have some optimization to do around high series counts (eg 1m) but reasonable series counts should perform well.
@jeremyforan can you be more specific about "fails intermittently"? Every other time? One in 10 times? Three times in a row and then not for 20 more tries?
I'd like to investigate more what specific complexity in the query causes challenges. What about queries like:
SELECT mean("ssid_scan_time") FROM "sample" WHERE "device_id" = 'hgf_hfx_17' AND time < now() - 20m GROUP BY time(1m) fill(null)SELECT COUNT("ssid_scan_time") FROM "sample" WHERE "device_id" = 'hgf_hfx_17' AND time > 1453352400s and time < now() GROUP BY time(1m) fill(null)SELECT MEAN("ssid_scan_time") FROM "sample" WHERE "device_id" = 'hgf_hfx_17' AND time > 1453352400s and time < now()
The first uses relative time range behavior rather than absolute time range behavior. The second uses MEAN() rather than COUNT(). The third uses raw data returns rather than GROUP BY.
I ran the first query 10 times without issue. The second query crashes influx each time I run it I ran the last query 10 times without issue.
I should note that I'm not drafting the queries manually but rather using grafana. if I run a query with a time window of 5 minutes, seems to work fine. If I expand it the window the queries break. These same dashboards worked in previous versions of influxdb and grafana.
Would it help to post the grafana dashboards?
Should be fixed in 0.11