我有一个名为“radacct”的 mysql innodb 表。此表包含用户互联网使用记录,如上传、下载、帐户 ID 等(下表架构如下)。该radacct
表使用路由器发送的数据以随机间隔更新。我们也使用这张表来计算互联网用户的总带宽,带宽计算查询(选择)大约需要 3-4 秒。当带宽计算查询和来自竞争锁的路由器的更新查询同时执行时,就会出现问题。这是由于 RepeatableRead 锁(表级锁定)和更好地在这里使用 ReadCommitted 隔离?
describe freeradius.radacct;
+----------------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------------------+-------------+------+-----+---------+----------------+
| radacctid | bigint(21) | NO | PRI | NULL | auto_increment |
| acctsessionid | varchar(32) | NO | MUL | | |
| acctuniqueid | varchar(32) | NO | MUL | | |
| username | varchar(64) | NO | MUL | | |
| groupname | varchar(64) | NO | | | |
| realm | varchar(64) | YES | | | |
| nasipaddress | varchar(15) | NO | MUL | | |
| nasportid | varchar(15) | YES | | NULL | |
| nasporttype | varchar(32) | YES | | NULL | |
| acctstarttime | datetime | YES | MUL | NULL | |
| acctstoptime | datetime | YES | MUL | NULL | |
| acctsessiontime | int(12) | YES | MUL | NULL | |
| acctauthentic | varchar(32) | YES | | NULL | |
| connectinfo_start | varchar(50) | YES | | NULL | |
| connectinfo_stop | varchar(50) | YES | | NULL | |
| acctinputoctets | bigint(20) | YES | | NULL | |
| acctoutputoctets | bigint(20) | YES | | NULL | |
| calledstationid | varchar(50) | NO | | | |
| callingstationid | varchar(50) | NO | | | |
| acctterminatecause | varchar(32) | NO | | | |
| servicetype | varchar(32) | YES | | NULL | |
| framedprotocol | varchar(32) | YES | | NULL | |
| framedipaddress | varchar(15) | NO | MUL | | |
| acctstartdelay | int(12) | YES | | NULL | |
| acctstopdelay | int(12) | YES | | NULL | |
| xascendsessionsvrkey | varchar(10) | YES | | NULL | |
+----------------------+-------------+------+-----+---------+----------------+
mysql> show session variables like '%isol%';
+---------------+-----------------+
| Variable_name | Value |
+---------------+-----------------+
| tx_isolation | REPEATABLE-READ |
+---------------+-----------------+
1 row in set (0.00 sec)
带宽计算查询
SELECT sum(acctinputoctets),sum(acctoutputoctets) from radacct
where username='davidjohnsoon' and acctstarttime
between '2015-10-11 14:10:17' and '2016-08-22 14:53:00'
插入/更新查询见mysql> show full processlist;
INSERT INTO radacct (acctsessionid, acctuniqueid, username, realm, nasipaddress, nasportid, nasporttype, acctstarttime, acctstoptime,acctsessiontime, acctauthentic, connectinfo_start, connectinfo_stop, acctinputoctets, acctoutputoctets, calledstationid, callingstationid, acctterminatecause,servicetype, framedprotocol, framedipaddress, acctstartdelay, acctstopdelay)
VALUES ('260204248', 'a5b889ad247a514b', 'johnson', '','100.44.44.44', '297797794', 'Ethernet', DATE_SUB('2016-08-23 13:02:50',INTERVAL (1 + 0) SECOND), '2016-08-23 13:02:50', '1', 'RADIUS', '', '', '0' << 32 | '0', '0' << 32 | '0','','90:61:0c:1a:94:96','User-Error','Framed-User', 'PPP', '','0', '0')