Java daemon

S

sl@exabyte

I gather that PHP daemon suffers from memory leak problem due to its garbage
collector mechanism.

Since java also adopts the garbage collector mechanism, would java daemon
suffers from the same memory problem ?

Thanks.
 
D

David Lamb

Since java also adopts the garbage collector mechanism, would java daemon
suffers from the same memory problem ?

There are several different ways to do garbage collection, so flaws in
one implementation have no bearing on what goes on with another.

The most common complaint that crosses implementations is the
unpredictability of when a gc happens, which can be a problem for a
program with serious real-time constraints. IIRC Java implementations
often have the gc run continuously and incrementally in a separate
thread, which evens out the effect.
 
A

Arne Vajhøj

I gather that PHP daemon suffers from memory leak problem due to its garbage
collector mechanism.

Since java also adopts the garbage collector mechanism, would java daemon
suffers from the same memory problem ?

PHP uses reference counting, which has some known problems (circular
references).

It is typical not a big problem in PHP due to everything going out
when request scope runs out.

(that of course does not cover native resources in extensions,
but Java does not do anything with those either)

There are many Java implementations and most of them support
multiple garbage collection algorithms, so it is difficult to say
what "Java" does.

But all the most popular uses some type of mark and sweep to
find what is still reachable and what is not.

That does not have the same problems as reference counting.

So assuming that you use a common Java implementation, then
you should not see the same problems as in PHP.

Arne
 
S

sl@exabyte

David said:
On 12/11/2012 9:17 AM, sl@exabyte wrote:

The most common complaint that crosses implementations is the
unpredictability of when a gc happens, which can be a problem for a
program with serious real-time constraints. IIRC Java implementations
often have the gc run continuously and incrementally in a separate
thread, which evens out the effect.

This is an interesting pointer/direction (I am new with java, but have done
quite some C/C++ on windows).

I have sort of given up hope on PHP daemon; one cannot touch its GC I
suppose. I am adamant to go C/C++; I have not done anything on Linux. I
suppose it would take too long a time to get it up and running (my target is
end of December 2012). So my next best option is java.
 
J

Jim Janney

sl@exabyte said:
I gather that PHP daemon suffers from memory leak problem due to its garbage
collector mechanism.

Since java also adopts the garbage collector mechanism, would java daemon
suffers from the same memory problem ?

Probably not: not all implementations of GC are equal, and you can't
generalize from one to another. For what it's worth, Twitter is in the
process of migrating from Ruby to Java due to problems with memory
management, and claims to be happy with the results:

http://www.theregister.co.uk/2012/11/08/twitter_epic_traffic_saved_by_java/
 
L

Lew

More likely it suffers from a packratting problem - failure to release memory.

Not the same problem, but you can force Java to hang on to object references long
past their usefulness, and eventually use up your available memory.

Idiomatic Java avoids this.
 
S

sl@exabyte

Martin said:
Actual Linux installation is fairly fast: the last install I did
(RedHat Fedora 17 on a dual 3GHz Athlon box with 4GB Ram) took about
the following times:

....

Acutally I mean the my c/c++ programming in Linux would probably take too
long a time to meet my target since I have done anything on Linux.
My server program has to process XML string and MySQL. I had a look at a
sample C program with MySQL API last night, it did not look that
intimidating. At this stage I am a bit encouraged to dip my little toe into
the Linux pool. But my programming experience tells me there are always
surprises. :)
 
A

Arne Vajhøj

More likely it suffers from a packratting problem - failure to release memory.

Reference counted GC has known problems even without packratting.
Not the same problem, but you can force Java to hang on to object references long
past their usefulness, and eventually use up your available memory.

Idiomatic Java avoids this.

And none of the common Java implementations use reference counting for GC.

Arne
 
A

Arne Vajhøj

I've not done a lot with PHP, but haven't (so far) run into any
particular problems with the Apache/PHP combination under Linux.

For the typical web page the request scope is sufficient to
avoid problems.

But a daemon is not a typical web page.

Arne
 
A

Arne Vajhøj

Acutally I mean the my c/c++ programming in Linux would probably take too
long a time to meet my target since I have done anything on Linux.
My server program has to process XML string and MySQL. I had a look at a
sample C program with MySQL API last night, it did not look that
intimidating. At this stage I am a bit encouraged to dip my little toe into
the Linux pool. But my programming experience tells me there are always
surprises. :)

The MySQL C API is indeed rather easy to work with.

If you have worked with PHP nysql or mysqli extensions, then it
will be even easier.

Arne
 
S

SL

sl@exabyte said:
Acutally I mean the my c/c++ programming in Linux would probably take
too long a time to meet my target since I have done anything on Linux.
My server program has to process XML string and MySQL. I had a look
at a sample C program with MySQL API last night, it did not look that
intimidating. At this stage I am a bit encouraged to dip my little
toe into the Linux pool. But my programming experience tells me there
are always surprises. :)

A correction, the statement "...since I have done anything on Linux" should
read "...since I have not done anything on Linux".
 
S

SL

David said:
There are several different ways to do garbage collection, so flaws in
one implementation have no bearing on what goes on with another.

The most common complaint that crosses implementations is the
unpredictability of when a gc happens, which can be a problem for a
program with serious real-time constraints. IIRC Java implementations
often have the gc run continuously and incrementally in a separate
thread, which evens out the effect.

I did some google'ing on garbage collector (GC) in java and found that it is
a big and complicated topic.
Java programmer has no permission to invoke it directly, beside juggling its
settings to adjust its frequency of running and the type of collector to
run. Even then how the GC is invoked stilll lies beyond programmer's
control.

It gets me thinking.

Why bother with it (people in the finance trade especially) ? Are the
advantages so great over c/c++ ? If the answer is yes, I can only think that
the reason is portability. Otherwise forget about tweaking GC; go for C/C++;
programmer has full control over memory management, and it is faster than
java.

I hope my opinion does not ignite the ire of java people.

I do have a question on GC: how to run the GC continuously ? Create a
thread, do some memory juggling to induce the GC to run ?
 
S

SL

Peter said:
Probably not. Most of the "Java people" are secure enough in their
knowledge that they are using the right tool for the job to not worry
about what some person grinding an anti-Java axe might have to say.
....

I have no axe to grind, Peter.

I have hardly programmed beyond "Helo World" in java. The above was just my
personal opinion, it could be very well wrong.

I am just hoping to learn some more esoteric facts about about java and
c/c++, which only people with a lot of experiece can give.

I remember what my former once said:

"Read about people's biograhy. They take a life time to attain their
achievements, and the reader takes 1 to 2 weeks to learn them. I don't think
there is a better deal."
 
A

Arved Sandstrom

I did some google'ing on garbage collector (GC) in java and found that it is
a big and complicated topic.
Java programmer has no permission to invoke it directly, beside juggling its
settings to adjust its frequency of running and the type of collector to
run. Even then how the GC is invoked stilll lies beyond programmer's
control.

It gets me thinking.

Why bother with it (people in the finance trade especially) ? Are the
advantages so great over c/c++ ? If the answer is yes, I can only think that
the reason is portability. Otherwise forget about tweaking GC; go for C/C++;
programmer has full control over memory management, and it is faster than
java.

I hope my opinion does not ignite the ire of java people.
[ SNIP ]

No ire on my part. I back up what Peter said (particularly with respect
to maintenance and reliability), and I'll add a few remarks of my own.

Think about why you'd want to invoke the Java GC yourself, and what that
would entail. You'd want to know *when* to do it - if you wrote the code
yourself to make that decision, and you were really good and really
experienced, it would probably look a lot like _existing_ code for some
GC or another. If you weren't that good then your code just wouldn't cut it.

By "code" I mean both the actual source and the GC parameters that you
can tune.

At first glance it might seem like this indirection - setting parameters
- removes a lot of control. That's not the case.

I'm not saying this is you - you already said it's not - but people who
assert that they can do better decision-making as to when to invoke a GC
run than the code that represents years of experience of GC specialists
strike me in the same vein as people who assert they can get better gas
mileage using manual stick than people who drive modern automatic
transmission cars. A very few people *can* do that - the majority (huge
majority) can't.

AHS
 
D

David Lamb

Why bother with it (people in the finance trade especially) ? Are the
advantages so great over c/c++ ? If the answer is yes, I can only think that
the reason is portability. Otherwise forget about tweaking GC; go for C/C++;
programmer has full control over memory management, and it is faster than
java.

GC has several big advantages over programmer control, one of them being
how often programmers get things wrong. A bug-free GC can be written
once, by experts, tested thoroughly, then lives on not subject to bugs
introduced by thousands of programmers across the hundreds of packages
you might use in any one program.

You never get reuse of already-deallocated memory, a classic source of
segmentation faults.

You never get the most common forms of memory leak, forgetting to
deallocate and losing the last pointer to the allocated memory. Though
people can misprogram to have long-lived structures point to ones no
longer needed; dunno how common that is. Technically this does not count
as a "memory leak"; rather it's "keeping data around too long that you
can still free eventually".

A compactifying GC can also *speed up* memory allocation and *reduce*
heap footprint by reducing fragmentation.
 
A

Arne Vajhøj

I've been picking it up from "Programming PHP" (O'Reilly). That doesn't
mention anything even vaguely resembling a PHP Daemon.

What is it?
If you have Apache, why would you need it?
Is it some sort of lightweight web server?

You know what a daemon is.

Besides the web integration with Apache and IIS that accounts
for 99+% of PHP usage, then PHP also comes with a command line
utility.

So you can write a daemon in PHP and run it via the command line
utility.

Arne
 
J

John B. Matthews

"SL" <[email protected]> said:
I do have a question on GC: how to run the GC continuously ? Create a
thread, do some memory juggling to induce the GC to run ?

On my platform, the JVM automatically spawns several threads to
facilitate garbage collection, including one called "Concurrent
Mark-Sweep GC Thread," which runs at a moderately lower priority than
the event queue. The host's scheduler uses multiple cores (when
available) to balance the load in favor of the user. The overall effect
is that even "busy" programs remain responsive, and I rarely notice GC
unless I'm looking for it, say in a profiler.

IIUC, the exact number and names of threads is platform-dependent. You
can use jvisualvm, included with the JDK, to see a thread timeline; or
you can take a snapshot of running threads via `kill -SIGQUIT pid`.
 
A

Arne Vajhøj

Thanks for the clarification. I thought you must have been talking about
some special PHP daemonising framework or library.

Nope. Just not very good at explaining what I meant.

Arne
 
A

Arne Vajhøj

Probably not: not all implementations of GC are equal, and you can't
generalize from one to another. For what it's worth, Twitter is in the
process of migrating from Ruby to Java due to problems with memory
management, and claims to be happy with the results:

http://www.theregister.co.uk/2012/11/08/twitter_epic_traffic_saved_by_java/

The article is not very specific - "manage memory more efficiently" do
not tell much about the issues.

But other sources explain. Ruby do use mark and sweep like Java and
not ref count as PHP. But it has no generations and are global stop
during the entire GC. Which is not as good as modern Java GC's.

Arne
 
A

Arne Vajhøj

PHP can deal with XML and interface to MySQL, though why anybody would
use it when using PostgreSQL has more standardised SQL and is as easy to
install for the same price, is more than I can imagine.

More users => better support.

And most of the non-standard SQL problems went away with
MySQL 4.1 and 5.0 back in 2005 and 2006.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top