"Translate" How many threads can--JVM support in a Redis article?

Source: Internet
Author: User

I read an article about Redis yesterday https://www.cnblogs.com/fanwencong/p/5782860.html

The author says he simulates the concurrency of 1 million of threads, and I have some doubts about this, and I read the commentary with a lot of questions. Of course, I'm not going to criticize the author for threading simulations, and the fact that the author writes about Redis is pretty good, and this article focuses on how many threads the JVM on a PC can support. Here is a question on stackoverflow, I have a simple translation.
StackOverflow The original answer please point me

Eddie's answer.

This depends on the CPU as you ' re using, on the OS, in what other processes is doing, on what Java release you ' re using, and other factors. I ' ve seen a WINDOWS server has > 6500 Threads before bringing the machine down. The most of the threads were is not doing anything, of course. Once the machine hits around 6500 Threads (in Java), the whole machine started to has problems and become unstable. My experience shows that Java (recent versions) can happily consume as many Threads as the computer itself can host Withou T problems. Of course, you has to have enough RAM and we have a started Java with enough memory to do everything that the thre Ads is doing and to has a stack for each Thread. Any machine with a modern CPUs (most recent couple generations of AMD or Intel) and with 1-2 Gig of memory (depending on OS) can easily support a JVM with thousands of threads.if you need a more specific answer than this, your best be T is to profile.

It depends on the CPU you use, the operating system, what other processes are dealing with, the Java version you use, and other factors. I've seen a Windows server that has more than 6,500 threads on it. Most threads are free, of course. Once the computer reaches 6,500 threads (in Java), the whole machine starts to have problems and becomes unstable. My experience is that no matter how many threads the computer itself can sustain, Java (the most recent version) can eat and not have problems. Of course you need enough RAM and you have to use enough memory to start Java to meet the needs of so many threads, and you need a stack to store the threads. Any computer that uses modern CPUs (the last two generations of AMD or Intel) and 1-2G memory (depending on the operating system) can support the JVM to create thousands of threads. If you need to answer more specific answers than this, the best option is to look at the relevant documentation.

Charlie Martin's answer

Um, lots.

There is several parameters here. The specific VM, plus there is usually run-time parameters on the VM as well. That's somewhat driven by the operating system:what support does the underlying OS has for threads and what limitations Does it put on them? If the VM actually uses os-level threads at all, the good old Red thread/green thread thing.

What ' support ' means is another question. If you write a Java program, that's just something like

   class DieLikeADog {         publicstaticvoidmain(String[] argv){             for(;;){                new Thread(new SomeRunaable).start();             }         }    }

(and Don ' t complain about little syntax details, I ' m on my first cup of coffee) then you should certainly expect to get Hu Ndreds or thousands of threads running. But creating a Thread is relatively expensive, and scheduler overhead can get intense; It's unclear that could has those threads do anything useful.

Update

Okay, couldn ' t resist. Here's my little test program, with a couple embellishments:

 Public classDielikeadog {Private StaticObject s =NewObject ();Private Static intCount =0; Public Static void Main(string[] argv) { for(;;) {NewThread (NewRunnable () { Public void Run(){synchronized(s) {Count + =1; System.Err.println("New Thread #"+count); } for(;;) {Try{Thread.Sleep( +); }Catch(Exception e) {System.Err.println(e); }                        }                    }                }).Start(); }    }}

On os/x 10.5.6 in Intel, and Java 6 5 (see comments), here's what I got

New thread #2547New thread #2548New thread #2549Can‘t create thread: 5New thread #2550Exception in thread "main" java.lang.OutOfMemoryError: unable to create new native thread        at java.lang.Thread.start0(Native Method)        at java.lang.Thread.start(Thread.java:592)        at DieLikeADog.main(DieLikeADog.java:6)

Translation:

Uh, a lot.

What ' support ' means is another question. If you write a Java program, that's just something like

There are many kinds of situations. Specific virtual machines, specific VMS, and often run-time parameters on VMS. It has something to do with the operating system: how does the operating system support multithreading and what are the restrictions on threading? If the VM is completely using an operating system-level thread, that is the red thread/green threading thing. (translation: This sentence does not quite understand)

What "support" means another problem. If you write a Java program, like this

   class DieLikeADog {         publicstaticvoidmain(String[] argv){             for(;;){                new Thread(new SomeRunaable).start();             }         }    }

(Don't complain about the grammatical details, I'm drinking the first cup of coffee today), you should expect to create hundreds of running threads. But creating a thread is expensive and the scheduler overhead becomes tense. It is unclear what useful things you can do with these threads.

Update

Okay, couldn ' t resist. Here's my little test program, with a couple embellishments:

Well, I can't stand the rebuttal. I'm giving you a simple test procedure.

 Public classDielikeadog {Private StaticObject s =NewObject ();Private Static intCount =0; Public Static void Main(string[] argv) { for(;;) {NewThread (NewRunnable () { Public void Run(){synchronized(s) {Count + =1; System.Err.println("New Thread #"+count); } for(;;) {Try{Thread.Sleep( +); }Catch(Exception e) {System.Err.println(e); }                        }                    }                }).Start(); }    }}

In the os/x 10.5.6 on Intel, and Java 6 5 (see Review) environment, I run the following results:

New thread #2547New thread #2548New thread #2549Can‘t create thread: 5New thread #2550Exception in thread "main" java.lang.OutOfMemoryError: unable to create new native thread        at java.lang.Thread.start0(Native Method)        at java.lang.Thread.start(Thread.java:592)        at DieLikeADog.main(DieLikeADog.java:6)

"Translate" How many threads can--JVM support in a Redis article?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.