我有一台服务器,它为连接到它的客户端对数据库进行多次写入。与它的联系越多,它的写作就越多。我的问题是..我怎样才能最优雅地处理这个?随着数据库变得越来越大,插入/更新花费的时间越来越长,这反过来又落后于客户端,因为来自服务器的响应越来越慢。
我想到的一件事是拥有一个 DB Helper 程序,我将其写入 QUEUE 数据库,并作为一个单独的应用程序,它将在分配时写入。这将使服务器更加专注,但我不确定这是否是最佳路线。
任何帮助都会很棒。
<Debug> -- 10/6/2012 8:57:15 PM -- UPDATE mapdata SET X = @1, Y = @2, Rank = @3, Health = @4, Beacons = @20,Armors = @5, Duals = @6, Missiles = @7, Homings = @8, Radars = @9, HasRankKill = @10, TotalPP = @11, RankPP = @12, KillCount = @13, DeathCount = @14, TimePlayed = @15, EnabledEquipment = @16 WHERE MapID = @17 AND TankID = @18 AND Color = @19;
<Debug> -- 10/6/2012 8:57:15 PM -- Time to execute: 00:00:00.0468003
这需要半秒钟才能执行。
我在 MapData 上有如下索引:
PRIMARY: MapID, TankID, Color
MapID: MapID
TankID: TankID
'MapData', 'CREATE TABLE `mapdata` (\n `MapID` int(11) NOT NULL,\n `TankID` int(11) NOT NULL,\n `Color` tinyint(4) NOT NULL,\n `X` int(11) DEFAULT \'-1\',\n `Y` int(11) DEFAULT \'-1\',\n `Rank` tinyint(4) NOT NULL DEFAULT \'0\',\n `Health` int(11) NOT NULL DEFAULT \'1200\',\n `Armors` tinyint(4) NOT NULL DEFAULT \'0\',\n `Duals` tinyint(4) NOT NULL DEFAULT \'0\',\n `Missiles` tinyint(4) NOT NULL DEFAULT \'0\',\n `Homings` tinyint(4) NOT NULL DEFAULT \'0\',\n `Radars` tinyint(4) NOT NULL DEFAULT \'0\',\n `Beacons` tinyint(4) NOT NULL DEFAULT \'0\',\n `HasRankKill` bit(1) NOT NULL DEFAULT b\'0\',\n `TotalPP` bigint(20) NOT NULL DEFAULT \'0\',\n `RankPP` bigint(20) NOT NULL DEFAULT \'0\',\n `KillCount` int(11) NOT NULL DEFAULT \'0\',\n `DeathCount` int(11) NOT NULL DEFAULT \'0\',\n `TimePlayed` time NOT NULL DEFAULT \'00:00:00\',\n `EnabledEquipment` tinyint(4) NOT NULL DEFAULT \'0\',\n `Prestige` tinyint(4) NOT NULL DEFAULT \'0\',\n PRIMARY KEY (`MapID`,`TankID`,`Color`),\n KEY `MapID` (`MapID`),\n KEY `TankID` (`TankID`),\n CONSTRAINT `mapdata_ibfk_1` FOREIGN KEY (`MapID`) REFERENCES `maps` (`ID`) ON DELETE CASCADE,\n CONSTRAINT `mapdata_ibfk_2` FOREIGN KEY (`TankID`) REFERENCES `tank` (`ID`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=latin1'