简体   繁体   中英

Issue with a real time chart with mysql connection

I want to show a real time chart but I haven´t had good results, I´m using canvasjs library and I use a mysql connection to do this but after some minutes receiving information, I have the next problem: [ 无法连接数据库:[1]

The data that I want to show comes from a medical device and this send around 1000 records per second , I can establish connection to receive the information but some minutes later this connection is lost, also I have a error in PHPMyadmin when i try to access:

在此处输入图片说明

If you can see is the same problem that I show you previously. Here is the query that I use to obtain the information from the database:

<?php
header('Content-Type: application/json');
$con = mysqli_connect("localhost", "root", "", "db");
if (mysqli_connect_errno($con)) {
 echo "Failed to connect to DataBase: " . mysqli_connect_error();
} else {
$data_points = array();
$result = mysqli_query($con, "SELECT * FROM values where id=10"); 
while ($row = mysqli_fetch_array($result)) {
$point = array("value1" => $row['valueX'], "value2" =>$row2['ValueY']);
    array_push($data_points, $point);
}
echo json_encode($data_points);
}
mysqli_close($con);
?>

If you have one suggestion or comment, please let me know. Thanks in advice.

100 per second is probably manageable without special actions.

Set up the browser to allow, say, 20 "clients".

Set up MySQL:

max_connections = 151 -- as it probably currently is
innodb_flush_log_at_trx_commit = 1  -- if using SSDs, else 2

Then there will probably be no problem gathering data at 100 web requests per second, leading to 100 MySQL INSERTs per second.

"1000" would probably have issues.

Meanwhile, you can fetch thousands of rows (in a single SELECT ) to produce your realtime chart. But don't do that 100 times per second.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM