AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Why my java code is THAT slow compared too C++?
Goto page 1, 2, 3 ... 330, 331, 332  Next
 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Language Programming
View previous topic :: View next topic  
Author Message
server
Guest





PostPosted: Sat Feb 11, 2006 11:23 pm    Post subject: Why my java code is THAT slow compared too C++? Reply with quote



message unavailable
Back to top
Roedy Green
Guest





PostPosted: Sat Feb 11, 2006 11:23 pm    Post subject: Re: Why my java code is THAT slow compared too C++? Reply with quote



On Sat, 11 Feb 2006 15:27:56 -0000, "Chris Uppal"
<chris.uppal (AT) metagnostic (DOT) REMOVE-THIS.org> wrote, quoted or indirectly
quoted someone who said :

Quote:
And given that the C++ version took 94 seconds,
most of these times you are comparing an single person writing both

programs. Usually they are expert in one language and inept in the
other. You must compare implementations by competent people, not a
hack port of one language to another.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Back to top
robert
Guest





PostPosted: Sat Feb 11, 2006 11:33 pm    Post subject: Re: stand-alone JMS, other JDBC operations, and transactions Reply with quote



Jesus M. Salvo Jr. escreveu:

Quote:
I need JDBC operations to be included with JMS transactions.

The quick answer would be to use JTA ... but I am not using any application
server nor any transaction manager.


I've never used JTOM, but I have used the transaction manager from the
spring framework, with lots of success.

http://www.springframework.org/docs/reference/transaction.html

Spring also has a lot of support for activemq:

http://activemq.org/Spring+Support

HTH,
robert
http://www.braziloutsource.com/
Back to top
Jacob
Guest





PostPosted: Sat Feb 11, 2006 11:36 pm    Post subject: Re: Matrix inversion algorithm examples Reply with quote

Robert M. Gary wrote:

Quote:
Does anyone have any code examples of doing a Matrix inversion that I
could look at?

This class inverts (check the invert() method) a 4x4 matrix
by the use of cofactors:

http://geosoft.no/software/matrix4x4/Matrix4x4.java.html

This is probably the fastest way to invert this type of
matrix, but might not be generalized to higher dimensions.

Quote:
I understand the graphics guys use matrices a lot too.

Yes, but we normally stop at 4x4...
Back to top
Guest






PostPosted: Sat Feb 11, 2006 11:51 pm    Post subject: Re: Multithreading / Scalability Reply with quote

In article <slrndun0i0.6gg.dima (AT) yellowtail (DOT) bmrb.wisc.edu>,
Dimitri Maziuk <abuse (AT) 127 (DOT) 0.0.1> wrote:
Quote:
blmblm (AT) myrealbox (DOT) com sez:

Are you saying that, if the goal is improve performance by splitting
computation among processors, this is better done with processes
than threads? Why?

Threads (as in "lightweight processes") were originally introduced
to avoid the overhead of process creation. Threads are not the
only solution: Plan 9 folks came up with low-overhead process
creation mechanism, Linux picked it up quickly. In a modern OS
with low-cost process creation mechanism the benefits of threads
(vs. processes) are small, and the overhead is an extra layer of
complexity.

Threads introduce an extra layer of complexity? Hm. I'm not sure
what you mean there ....:

I can believe that in current operating systems it's almost as fast
to create processes as to create threads. Context switch times
might also need to be taken into account, but maybe there too the
difference is not really significant.

But my understanding is that a key difference between threads and
processes is that the former share an address space and the latter
do not, and this leads to rather different programming models --
communication via message-passing versus communication via shared
variables. Shared variables in some ways seem easier and more
natural, but the need for synchronization means that there are lots
of potential pitfalls. Message passing is less easy/natural but
avoid some of the potential pitfalls.

All of this is of course moot if the threads/processes are totally
independent. I'm coming to this discussion from a background in
parallel computing, though, where the threads/processes are rarely
*completely* independent.

Quote:
This is a moot point in Java, of course, since Java only has
threads. There Is No Fork().

Um, no, but doesn't the "exec" method in Runtime do something along
those lines? I have zero experience working with this method; I'm
going by the API and by vague recollections of discussions in this
group.

Quote:
... But if you can do either one and want maximum performance,
it seems to me that threads are the way to go. Do you disagree?

Two main sources of overhead are initial creation and
synchronization. If they are fully independent (no
synchronization) and long-running (creation cost amortized
to close to 0 over runtime), there should be no difference
between threads and processes performance-wise.

Probably so. I wasn't really thinking of totally independent
threads/processes.

Also, if you're using the additional threads/processes to mask
latency, then context switch times need to be taken into account.
Maybe there too the difference is less than I think -- threads
would seem to win out, but perhaps not by much.

Quote:
you want to use threads for what they're designed: server-type
processes that read data from multiple inputs or perform other
asynchronous tasks with less overhead than processes.

Or to improve performance if you have more than one processor. (Or
even if you don't, and your code can be split up into threads in a way
that allows one thread to make progress while another thread waits
for something to happen, I/O for example -- i.e., if threads can be
used to "mask latency".)

Only if you have several execution streams that can run
asynchronously.

Sure. I do enough of this multithreading-for-performance (as a
research interest more than for practical reasons) that I'm apt to
forget that not everyone thinks in those terms, maybe.

Quote:
Anyway, the real deal is that threads don't economically scale
past 4 CPUs (4-way being the cusp of bang-per-buck curve) and
thus 4-16 threads: e.g. Sun will happily sell you a 24-CPU
cupboard for a cool million bucks, or 24 1-CPU pizza boxen for
about $18,000. Which means that if you're doing it for scalability,
you're way better off going fully distributed (hence, independent
processes) or with some specialized grid/cluster setup (probably
different programming techniques altogether).

Traditionally this has been true, yes. I wonder if it will continue
to be true in the next few years -- dual-core chips are not the
rare beasts they were a few years ago, and one hears so much about
multicore chips in general that I wonder whether in a few years
there won't be a lot more 4-way and 8-way systems .... But I'm
not a hardware designer, and it may be that there's still no way
to make shared-memory systems scalable.

In any case, it seems to me that arguments about scalability, while
interesting and important, miss the point that if what you have is
a 2-processor or 4-processor system, a program that exploits the
extra processors is a good thing to have, even if it doesn't scale
to more than 4 processors.

Just some thoughts / my two cents' worth.

--
| B. L. Massingill
| ObDisclaimer: I don't speak for my employers; they return the favor.
Back to top
Alun Harford
Guest





PostPosted: Sun Feb 12, 2006 12:22 am    Post subject: Re: cpu intesive jave program Reply with quote

"puzzlecracker" <ironsel2000 (AT) gmail (DOT) com> wrote in message
news:1139678963.947096.35510 (AT) g14g2000cwa (DOT) googlegroups.com...
Quote:
Is there a java library or "anything" I can use to increment CPU (used
percent) in a controlled matter? For example, I want to write a program
that can increase cpu by 25%. It is probably platform specific.

Any suggestions would be appreciated.

You need to be running in kernel mode on most systems. While, in theory,
there's nothing to stop you putting a JVM in your kernel, it's never been
done (it would be *horrible*, but it would be worth doing for comedy value).

Basically, you need some way of hooking into the scheduler, or know exactly
what the other processes on the system are doing.

Alun Harford
Back to top
Thomas Hawtin
Guest





PostPosted: Sun Feb 12, 2006 12:41 am    Post subject: Re: Why my java code is THAT slow compared too C++? Reply with quote

Kevin wrote:
Quote:
It is not my java code's prolem.

I disagree.

Quote:
I found the detailed guide for the c++ program.
It turned out that the data file is in a format that favor that c++
code: it encodes the hash value of each word into the file already
(which I previously thought was just some part of the data).

My initial reaction to reading that was: "Oh my god, you don't want to
do that."

This really should be a I/O bound problem. Adding extra data is not the
way to may it faster.

Quote:
So the c code does not need to do the hash step, only the count step.

That is not necessarily why the C code is faster.

Quote:
After I took that special data format into my code, my java code runs
as fast as the c++ code.

You are changing more than you think you are.

I didn't look through your code first time around because it had been
made unnecessarily difficult to read.

Looking at it again my first thought was that you were repeatedly
calculating the hash code every time. When you changed the program to
read the hash code from the file, you presumably stopped doing that.
Even so, the method should not be executed frequently.

Looking at the hash algorithm, it doesn't look conventional. Effectively
what you have is:

Sum s[i] * ((2^5 - 1) ^ i+1)

The binary representation of powers of one less than a power of two are
not as "random" as you might think, particularly in the last few binary
digits. For a hash map/table this may result in poor distribution of
entries and hence very poor performance.

The exact impact will depend upon the implementation of the hash map.
Using HashMap on Sun's 1.4.1 may well turn out to be much slower than in
1.4.0 or 1.4.2.

The importance of reading the hash code from the file was that it is
calculated with a better algorithm. That appears to have transformed the
I/O bound problem into a CPU bound solutions.

Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
Back to top
Vojta
Guest





PostPosted: Sun Feb 12, 2006 12:41 am    Post subject: Re: Sets like in Delphi? Reply with quote

Thank you all a lot for your help! Vojta Surprised)

"Roedy Green" <my_email_is_posted_on_my_website (AT) munged (DOT) invalid> píse v
diskusním príspevku news:odasu1tfvpa35gch6si76sogr36fc1k4jg (AT) 4ax (DOT) com...
Quote:
On Sat, 11 Feb 2006 16:07:38 +0100, "Vojta" <ryvo (AT) centrum (DOT) cz> wrote,
quoted or indirectly quoted someone who said :

TFruit = (ftApple, ftOrange, ftBanana ...);
TFruits = set of TFruit;

Is it possible to the same in Java?
see http://mindprod.com/jgloss/enum.html

It is more complex that Delphi, but it can do more powerful thing.s
See also Enumset.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Back to top
puzzlecracker
Guest





PostPosted: Sun Feb 12, 2006 12:41 am    Post subject: Re: cpu intesive jave program Reply with quote

Quote:
Basically, you need some way of hooking into the scheduler, or know exactly
what the other processes on the system are doing.


do i really need know what other processes are doing? Let's say I am
not concerned with current percentage, but only with a value I want it
to boost to.

ex. currently cpu%=50
I want to to raise it by 20%, and that is fine if some other processes
raise it by some value n during interupts....

All I care is to know that my call can raise it if there is a room.
That is all.
Back to top
Chris Smith
Guest





PostPosted: Sun Feb 12, 2006 12:41 am    Post subject: Re: JAVA MAIL Reply with quote

Roedy Green <my_email_is_posted_on_my_website (AT) munged (DOT) invalid> wrote:
Quote:
it uses POP3 or imap or is it mapi (I can never remember which is
which).

It's IMAP.

MAPI is a (now obsolete) API for client-side code to interact with the
message store in Microsoft Outlook. It is not a network protocol.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Back to top
tom fredriksen
Guest





PostPosted: Sun Feb 12, 2006 12:41 am    Post subject: Re: Why my java code is THAT slow compared too C++? Reply with quote

Roedy Green wrote:
Quote:
On Sat, 11 Feb 2006 14:24:05 +0100, tom fredriksen
tom@spam-me-not.net> wrote, quoted or indirectly quoted someone who
said :

. What you have to do is read
the processors current millisecond counter

With 1.5 there is an ever more accurate nanosecond timer. See
http://mindprod.com/jgloss/time.html

I know. But not really the point, as you are dealing with an operation
that is measured in minutes and seconds.

/tom
Back to top
none
Guest





PostPosted: Sun Feb 12, 2006 12:41 am    Post subject: Re: Tomcat on Linux Platform Reply with quote

tom fredriksen wrote:
Quote:
mania wrote:

Hello,

I have installed tomcat 5.5.15 on Fedora Core 3 , it is
running on the host but when i want to access it from remote machine
using IP address of server ( host on which tomcat is running ) it is
showing the error. The error is Gateway could not retrive the page. Can
anybody suggest me that how to do that?? I used the defult port 8080.


Generally that is the way to do it.

Does it work from the local machine or across a network? do you have a
local firewall or a router w/firewall in between? You can also check the
catalina log file so see whether tomcat receives a request at all.

/tom
double check tomcat's server.xml for the configuration of the host

element, as it may be listening on localhost or 127.0.0.1 and won't be
accessible from a remote machine. If so, change this to the domain name/
public ip of the box.

Tim
Back to top
tom fredriksen
Guest





PostPosted: Sun Feb 12, 2006 12:41 am    Post subject: Re: HI, Reply with quote

ravindra.csd (AT) gmail (DOT) com wrote:
Quote:
Hi,
I don't have any knowledge about web application.Can you please tell me
about web application tools or framework?

can you list some tools?

You could also search wikipedia.org for the words your are talking about
it should produce some articles of interrest for you

/tom
Back to top
tom fredriksen
Guest





PostPosted: Sun Feb 12, 2006 12:41 am    Post subject: Re: Fine Tunning Java for performance Reply with quote

titogeo wrote:
Quote:
Can any one tell my to access all the available memory from within the
program. i tried a program which takes file and do some manipulations
and write it back. But i cant take files above 20 Mb. How i can
increase the heap size for program.

RTFM

or

you could try googling for words like "java set heap size".

/tom
Back to top
tom fredriksen
Guest





PostPosted: Sun Feb 12, 2006 12:41 am    Post subject: Re: max heap size on 32 bit linux ? Reply with quote

You could possibly try to use vmstat and such tools to track the system
memory to see which process is using what memory. By doing this, you at
least, are able to verify where the memory problem is.

There are is a linux tool called memtest86 which performs all from
simple to complex memory testing, which you could use the check for
memory problems. It can take a while for the complex tests though,
perhaps a day or two (it should run a couple of iterations).

There is also a linux hardware diagnostics program (dont remember the
name of it) which will test the entire system to see if there are any
devices or components with problems.

If none of these things turn up anything then your best bet might
probably be to profile or diagnose the program it self.

/tom

iksrazal (AT) gmail (DOT) com wrote:
Quote:
Hi all,

We've recently aquired a new dual processor 3.0GHZ Xeon running Suse
9.2 . It has 4 gigs of ram. However, the JVM is crashing daily. Our app
has never shown this behavior before - though it never has run on a
machine with more than I gig of ram. Its a tomcat webapp running
hibernate. Here's the JVM args we pass to tomcat:

CATALINA_OPTS="-server -Xms512m -Xmx2048m -Xincgc -XX:PermSize=128m
-XX:MaxPermSize=512m"

We're seeing errors like:

Exception in thread "CompilerThread0" java.lang.OutOfMemoryError:
requested 1801688 bytes for Chunk::new. Out of swap space?

and:

#
# An unexpected error has been detected by HotSpot Virtual Machine:
#
# SIGSEGV (0xb) at pc=0xb2b5027f, pid=3630, tid=38177712
#
# Java VM: Java HotSpot(TM) Server VM (1.5.0_06-b05 mixed mode)
# Problematic frame:
# J java.lang.StringCoding.encode(Ljava/lang/String;[CII)[B
#

Even though the machine's load average (top) is under 1. This machine
has a low load until it hits production.

I did set the ulimit:

ulimit -s 3072

I've also tried 2048.

So my question is: Can I safely allocate 2048 megs on 32 bit intel
running linux, with 4 gigs total and nothing else running that's heavy?
What's the max I can allocate?

iksrazal
http://www.braziloutsource.com/
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Language Programming All times are GMT
Goto page 1, 2, 3 ... 330, 331, 332  Next
Page 1 of 332

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.