Java daemon

Discussion in 'Java' started by sl@exabyte, Nov 12, 2012.

  1. sl@exabyte

    sl@exabyte Guest

    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.
    sl@exabyte, Nov 12, 2012
    #1
    1. Advertising

  2. sl@exabyte

    David Lamb Guest

    On 12/11/2012 9:17 AM, sl@exabyte wrote:
    > 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.
    David Lamb, Nov 12, 2012
    #2
    1. Advertising

  3. sl@exabyte

    Arne Vajhøj Guest

    On 11/12/2012 9:17 AM, sl@exabyte wrote:
    > 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
    Arne Vajhøj, Nov 12, 2012
    #3
  4. sl@exabyte

    sl@exabyte Guest

    David Lamb wrote:
    > 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.
    sl@exabyte, Nov 12, 2012
    #4
  5. sl@exabyte

    Jim Janney Guest

    "sl@exabyte" <> writes:

    > 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/

    --
    Jim Janney
    Jim Janney, Nov 12, 2012
    #5
  6. sl@exabyte

    Lew Guest

    Jim Janney wrote:
    > "sl@exabyte" writes:
    >> I gather that PHP daemon suffers from memory leak problem due to its garbage
    >> collector mechanism.


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

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


    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.

    --
    Lew
    Lew, Nov 12, 2012
    #6
  7. sl@exabyte

    sl@exabyte Guest

    Martin Gregorie wrote:
    >>

    > 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. :)
    sl@exabyte, Nov 13, 2012
    #7
  8. sl@exabyte

    Arne Vajhøj Guest

    On 11/12/2012 4:35 PM, Lew wrote:
    > Jim Janney wrote:
    >> "sl@exabyte" writes:
    >>> I gather that PHP daemon suffers from memory leak problem due to its garbage
    >>> collector mechanism.

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


    Reference counted GC has known problems even without packratting.

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

    >
    > 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
    Arne Vajhøj, Nov 13, 2012
    #8
  9. On 11/12/2012 5:07 PM, Martin Gregorie wrote:
    > On Mon, 12 Nov 2012 23:55:58 +0800, sl@exabyte wrote:
    >> 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'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
    Arne Vajhøj, Nov 13, 2012
    #9
  10. sl@exabyte

    Arne Vajhøj Guest

    On 11/12/2012 9:56 PM, sl@exabyte wrote:
    > Martin Gregorie wrote:
    >>>

    >> 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. :)


    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
    Arne Vajhøj, Nov 13, 2012
    #10
  11. sl@exabyte

    SL Guest

    sl@exabyte wrote:

    > 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".
    SL, Nov 13, 2012
    #11
  12. sl@exabyte

    SL Guest

    David Lamb wrote:
    > On 12/11/2012 9:17 AM, sl@exabyte wrote:
    >> 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.


    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 ?
    SL, Nov 13, 2012
    #12
  13. sl@exabyte

    SL Guest

    Peter Duniho wrote:
    >
    > 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."
    SL, Nov 13, 2012
    #13
  14. On 11/13/2012 02:40 AM, SL wrote:
    > David Lamb wrote:
    >> On 12/11/2012 9:17 AM, sl@exabyte wrote:
    >>> 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.

    >
    > 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
    Arved Sandstrom, Nov 13, 2012
    #14
  15. sl@exabyte

    David Lamb Guest

    On 13/11/2012 1:40 AM, SL wrote:
    > David Lamb wrote:
    >> On 12/11/2012 9:17 AM, sl@exabyte wrote:
    >>> 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.

    > 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.
    David Lamb, Nov 13, 2012
    #15
  16. On 11/13/2012 4:36 PM, Martin Gregorie wrote:
    > On Mon, 12 Nov 2012 22:06:50 -0500, Arne Vajhøj wrote:
    >> On 11/12/2012 5:07 PM, Martin Gregorie wrote:
    >>> On Mon, 12 Nov 2012 23:55:58 +0800, sl@exabyte wrote:
    >>>> 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'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.
    >>

    > 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
    Arne Vajhøj, Nov 13, 2012
    #16
  17. In article <k7sq0e$poi$>, "SL" <>
    wrote:

    > 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`.

    --
    John B. Matthews
    trashgod at gmail dot com
    <http://sites.google.com/site/drjohnbmatthews>
    John B. Matthews, Nov 14, 2012
    #17
  18. On 11/14/2012 4:33 PM, Martin Gregorie wrote:
    > On Tue, 13 Nov 2012 17:31:22 -0500, Arne Vajhøj wrote:
    >
    >> 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.
    >>

    > 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
    Arne Vajhøj, Nov 14, 2012
    #18
  19. sl@exabyte

    Arne Vajhøj Guest

    On 11/12/2012 4:24 PM, Jim Janney wrote:
    > "sl@exabyte" <> writes:
    >
    >> 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/


    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
    Arne Vajhøj, Nov 18, 2012
    #19
  20. On 11/13/2012 4:50 PM, Martin Gregorie wrote:
    > On Tue, 13 Nov 2012 10:56:47 +0800, sl@exabyte wrote:
    >> My server program has to process XML string and MySQL.
    >>

    > 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
    Arne Vajhøj, Nov 18, 2012
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. calvin01
    Replies:
    5
    Views:
    16,373
  2. Fatih
    Replies:
    4
    Views:
    13,876
    Fatih
    Apr 9, 2004
  3. Jean-Paul Calderone
    Replies:
    0
    Views:
    447
    Jean-Paul Calderone
    Mar 20, 2009
  4. Floris Bruynooghe
    Replies:
    1
    Views:
    443
    Floris Bruynooghe
    Mar 24, 2009
  5. Daemon Win32::Daemon;

    , Sep 7, 2006, in forum: Perl Misc
    Replies:
    0
    Views:
    240
Loading...

Share This Page