Databases 10 min read

Why Choose InfluxDB? A Deep Dive into Time‑Series Database Benefits and Setup

This article explains why InfluxDB stands out among time‑series databases by covering its performance, storage model, use cases, comparison with relational databases, line protocol fundamentals, Docker installation steps, and PHP client integration, providing a practical guide for developers.

Open Source Tech Hub
Open Source Tech Hub
Open Source Tech Hub
Why Choose InfluxDB? A Deep Dive into Time‑Series Database Benefits and Setup

Why InfluxDB?

When selecting a time‑series database, the most critical factors are storage and query performance, space efficiency, and flexible scalability; InfluxDB excels in these areas and has rapidly overtaken older solutions like RRDTool and Graphite.

Introduction

InfluxDB is an open‑source time‑series database written in Go, designed for monitoring data. It includes built‑in functions such as standard deviation, random sampling, and change‑rate calculations, making real‑time analytics convenient.

The single‑node version is free, while the clustered edition is commercial. InfluxDB is optimized for SSD storage; using slower disks can degrade performance by an order of magnitude. It supports a Restful API and HTTPS for secure remote access.

Use Cases

InfluxDB is typically used in monitoring scenarios for operations and IoT, where time‑stamped metrics are stored and processed in real time.

Example: a program writes CPU usage every 10 seconds to InfluxDB, queries the 30‑second average, and repeats the query every 10 seconds. An alert rule triggers when the result exceeds a threshold.

Similar monitoring needs exist for IoT devices, such as bearing vibration frequencies or field humidity.

Why Not Relational Databases?

Write Performance

Relational databases use B‑tree structures, which can cause leaf splits and random disk I/O during writes, slowing down ingestion.

Most time‑series databases, including InfluxDB, adopt variants of LSM‑Tree that write sequentially to disk, achieving tens of thousands of writes per second per node.

Data Value

Monitoring data exhibits a clear hot‑cold pattern: recent data is frequently accessed (hot) while older data can be compressed and stored on disk (cold). InfluxDB’s architecture separates hot and cold data accordingly.

Immutable Time‑Series

Time‑series records are immutable; once written, they are never modified, which aligns with the insert‑heavy workload of such databases.

Storage Model

Each InfluxDB record includes a measurement (similar to a table), a timestamp, at least one field (key‑value pair), and optional tag key‑value pairs.

Compared to MySQL, measurement maps to a table, timestamp is the primary key, and tag / field correspond to columns. Tags are indexed, while fields are not, affecting query performance.

Note: MySQL tables require a predefined schema, whereas InfluxDB measurements are schema‑less; null values are not stored.

Measurements can be created on the fly without prior definition, but a field’s data type must remain consistent across writes.

Theory and Principles

InfluxDB Line Protocol

Telegraf’s internal data format is the InfluxDB line protocol. Each line represents a data point and consists of four elements separated by spaces.

measurement (measurement name)

tag set

field set

timestamp

Installation & Deployment

Pull the Docker image: docker pull influxdb Run the container:

docker run -d -p 8086:8086 --name influxdb influxdb

Access the service at http://127.0.0.1:8086.

Initialize a user via the web UI (screenshots omitted).

Enter the container shell if needed:

docker exec -it <container_id> sh

PHP Client Integration

The official client libraries support many languages; the following shows PHP integration.

Install via Composer:

composer require influxdata/influxdb-client-php guzzlehttp/guzzle

Example PHP script ( influxdb.php) creates a client, writes a data point, and queries recent data:

<?php
declare(strict_types=1);
require_once '../vendor/autoload.php';
use InfluxDB2\Client;
use InfluxDB2\Model\WritePrecision;
$token = 'Kmdv_gAm2EEWDpPCBdC4cTbkT_rUa1UsDBNvhTh1cn0Sc7P0emgtsIL35hRlV0XSKQLSVesC4MEuViDN55bCug==';
$org = '开源技术小栈';
$bucket = 'resty';
$client = new Client([
    "url" => "http://192.168.3.29:8086",
    "token" => $token
]);
$writeApi = $client->createWriteApi();
$data = "mem,host=host1 used_percent=23.43234543";
$writeApi->write($data, WritePrecision::S, $bucket, $org);
$query = "from(bucket: \"resty\") |> range(start: -1h)";
$tables = $client->createQueryApi()->query($query, $org);
foreach ($tables as $table) {
    foreach ($table->records as $record) {
        $time = $record->getTime();
        $measurement = $record->getMeasurement();
        $field = $record->getField();
        $value = $record->getValue();
        print "{$time} {$measurement}: {$field}={$value}
";
    }
}
?>

Run the script: php influxdb.php The output shows the written data point, confirming successful write and query.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DockerTime Series DatabasePHPInstallationInfluxDB
Open Source Tech Hub
Written by

Open Source Tech Hub

Sharing cutting-edge internet technologies and practical AI resources.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.