Computing.Net > Forums > Linux > Flat File To MYSQL - EVEN WORSE

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Flat File To MYSQL - EVEN WORSE

Reply to Message Icon

Name: Jamie_McCoy
Date: July 31, 2005 at 04:44:11 Pacific
OS: XP Pro 5.1
CPU/Ram: Pentium 4 2.4Ghz
Comment:

OK so i have a very busy website, which used to use a flat file database system for members

i have just covnerted it to run completely from MYSQL, however now with 200 users online MYSQL is going crazy

Im fairlly new to MYSQL, so im not aware of common programming issues that may cause crashes or lock ups

Load = 20, 30, 40..... i look at TOP and see 279 Processes


CPU states: cpu user nice system irq softirq iowait idle
total 78.2% 0.0% 20.3% 0.5% 0.7% 0.0% 0.0%

I also see a lot of mysql <defunct> in TOP


Here is an example of the type of commands that are being run by each user every time they click a link, so its 200 X whats below near enough

At first i thoguht it might be because i never had any 'LIMIT 0,1' its the commands, but as you can see ive added them now

the DATABASE in questions is the members one, its 4.5MB and has 26,000 users

// fullname
$query="SELECT * FROM members WHERE username='$page' LIMIT 0,1";
$result=mysql_query($query);
$fullname=mysql_result($result,'id',"fullname");


// username
$query="SELECT * FROM members WHERE username='$page' LIMIT 0,1";
$result=mysql_query($query);
$usered=mysql_result($result,'id',"username");

// nickname
$query="SELECT * FROM members WHERE username='$page' LIMIT 0,1";
$result=mysql_query($query);
$nickname=mysql_result($result,'id',"nickname");


// visits
$query="SELECT * FROM members WHERE username='$page' LIMIT 0,1";
$result=mysql_query($query);
$visits=mysql_result($result,'id',"visits");


$browsin="UPDATE members SET browsing = '$rowed' WHERE username = '$usered'";
mysql_query($browsin) or die(mysql_error());

$lastact="UPDATE members SET lastact = '$dated' WHERE username = '$usered'";
mysql_query($lastact) or die(mysql_error());


$song="UPDATE members SET lastsongs = '$lastsongsdone' WHERE username = '$usered'";
mysql_query($song) or die(mysql_error());


mysql_close();

Any help would be greatly appreciate, my site is basically dying, takes 15 seconds for each page to load....

Jamie McCoy



Sponsored Link
Ads by Google

Response Number 1
Name: FishMonger
Date: July 31, 2005 at 09:50:42 Pacific
Reply:

Instead of mssql_query, you should use mssql_fetch_array which will be faster and (in a single querry) put all the info into an associative array.

I use Perl instad of php, so you may need to verify if this syntax is correct.

$query="SELECT fullname, username, nickname, vists FROM members WHERE username = '$page' LIMIT 0,1";
$result = mssql_fetch_array($query) or die("could not query the database");

Now, you can access the info via
$result{'fullname'}
$result{'username'}
$result{'nickname'}
$result{'visits'}


0

Response Number 2
Name: FishMonger
Date: July 31, 2005 at 09:56:44 Pacific
Reply:

The UPDATE should be done in a similar manor, meaning use a single sql update command instead of each of those individual ones.

By making both of those changes, you should dramatically increase its efficiency.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Linux Forum Home


Sponsored links

Ads by Google


Results for: Flat File To MYSQL - EVEN WORSE

Convert delimited file to Flat File www.computing.net/answers/linux/convert-delimited-file-to-flat-file/29428.html

Samba + MySQL + W2K + RH7.1 www.computing.net/answers/linux/samba-mysql-w2k-rh71/7541.html

convert MS acces to mysql BDB www.computing.net/answers/linux/convert-ms-acces-to-mysql-bdb/17042.html