MySQL Forums
Forum List  »  Performance

Java vs MySQL
Posted by: Sxo Pi1
Date: June 09, 2009 09:01AM

Hi all,
to optimize performance of some calculations on huge data we rewrite some java logic to stored procedures on MySQL side. Removing app/db transport should lead to performance progress but instead we noticed regress. At this point bottle neck localized at mathematical functions calculations. This is confusing. Should this be so or am i wrong? Time difference is about 99.8% for benefit of java!!!

MySQL test:

DROP PROCEDURE IF EXISTS TEST_PERF;
CREATE PROCEDURE TEST_PERF
(IN loop_count INT)
BEGIN
DECLARE lt1, ln1, lt2, ln2 DECIMAL(10,5);
DECLARE rlt1, rlt2, rln1, rln2, s1, s2, c1, c2, sd, cd DECIMAL(10,5);
DECLARE i INT DEFAULT 0;
DECLARE tdiff TIMESTAMP;

SET tdiff=NOW();
loop1: LOOP
IF i>loop_count THEN
LEAVE loop1;
END IF;
SET lt1=RAND()*100;
SET ln1=RAND()*100;
SET lt2=RAND()*100;
SET ln2=RAND()*100;

SET rlt1 = RADIANS(lt1);
SET rln1 = RADIANS(ln1);
SET rlt2 = RADIANS(lt2);
SET rln2 = RADIANS(ln2);
SET s1 = SIN(rlt1);
SET s2 = SIN(rlt2);
SET c1 = COS(rlt1);
SET c2 = COS(rlt2);
SET sd = SIN(rln1 - rln2);
SET cd = COS(rln1 - rln2);
SET i=i+1;
END LOOP loop1;
END;
call TEST_PERF(1000000);


Java test:
public static void main(String[] args) {
long t1 = System.currentTimeMillis();
testPerf();
long t2 = System.currentTimeMillis();
System.out.println("executed in " + (t2 - t1));
}

public static void testPerf(){
double rlt1, rln1, rlt2, rln2, lt1, ln1, lt2, ln2, s1, s2, c1, c2, sd, cd;
for (int i=0; i<1000000; i++){
lt1 = Math.random()*100;
lt2 = Math.random()*100;
ln1 = Math.random()*100;
ln2 = Math.random()*100;

rlt1 = Math.toRadians(lt1);
rln1 = Math.toRadians(ln1);
rlt2 = Math.toRadians(lt2);
rln2 = Math.toRadians(ln2);

s1 = Math.sin(rlt1);
s2 = Math.sin(rlt2);
c1 = Math.cos(rlt1);
c2 = Math.cos(rlt2);

sd = Math.sin(rln1 - rln2);
cd = Math.cos(rln1 - rln2);
}
}

Options: ReplyQuote


Subject
Views
Written By
Posted
Java vs MySQL
5032
June 09, 2009 09:01AM
2030
June 09, 2009 07:08PM
3068
June 10, 2009 01:48AM
2048
June 10, 2009 09:07AM
1915
June 17, 2009 08:34AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.