질문] Linux 에서 java 통해 쓰레드 1024 개 이상생성하신분 ?

kikakika의 이미지

linux 에서 이상하게 native 쓰레드 개수가 1024개를 넘지 못합니다.

물론 윈도우에서는 2000개 3000개 잘 생성됩니다.

Linux 를 default 로 설치 하고 java 실행을 해본 결과

Exception in thread "main" java.lang.OutOfMemoryError: unable to create new native thread
at java.lang.Thread.start(Native Method)
at ThreadOverhead.overheadTest(ThreadOverhead.java:21)
at ThreadOverhead.main(ThreadOverhead.java:6)

이런 에러가 발생합니다. 물론 이건 OutOfMemoryError 가 아닌 native thread 생성 에러 입니다.

아래 프로그램을 컴파일 하고 돌려 보시면 알수 있을 겁니다.
(마이크로 소프트 2002 년 기사중에 있던 ThreadOverhead.java 라구 쓰레드의 컨텍스트 전환에 대한 시간 측정 프로그램을 좀더 정확하게 측정하게 수정한것입니다. )

>java ThreadOverhead 1000

>java ThreadOverhead 2000

>ps -ef | grep ThreadOverhead | wc // native 쓰레드 개수를 확인 , +1 은 grep 프로세스 일겁니다. (그냥 빼고 생각하세요)
1025

혹시 linux 에서 1024개 이상 쓰레드를 생성하신 분 있으면 리플 부탁 드립니다.

----------------------------------------------------------

public class ThreadOverhead implements Callback {
private int threadCount;
private long totalMsec;

public static void main(String[] args) throws Exception {
new ThreadOverhead().overheadTest(Integer.parseInt(args[0]));
}

public void overheadTest(int threadCount) throws Exception {
this.threadCount=threadCount;
TestThread[] threads = new TestThread[threadCount];
System.out.println();
for(int i=0;i<threads.length; i++)
{
threads[i] = new TestThread(this);
System.out.print("\r"+i);
}
System.out.println("\nthread num : "+threads.length);
System.out.println();
for(int i=0;i<threads.length; i++)
threads[i].start();

while(true) {
Thread.sleep(100);
//System.out.println("\r"+TestThread.Count);
if(TestThread.Count==threads.length)
break;

}
System.out.println("threads started");
synchronized(TestThread.SyncObj) {
TestThread.SyncObj.notifyAll();
}

waitForAllThreads();
System.out.println("thread num : "+threadCount );
System.out.println("threads(s) : " + (totalMsec / threadCount));
}
public synchronized void reset() {
this.totalMsec=0;
}
public synchronized void workCompleted(long msec) {
totalMsec += msec;
threadCount -- ;

this.notify();
}
public synchronized void waitForAllThreads() throws Exception {
while(threadCount> 0) this.wait();
}

}

interface Callback {
void workCompleted(long msec) ;
}

class TestThread extends Thread {
private Callback callback ;
public static Object SyncObj=new Object();
public static int Count=0;

public TestThread(Callback callback)
{
this.callback = callback ;
}
public void run() {
try {

synchronized(SyncObj) {
Count++;
}
synchronized(SyncObj) {
SyncObj.wait();
}

long startMsec = System.currentTimeMillis();
for(int i=0;i<1000; i++)
Thread.sleep(10);
callback.workCompleted(System.currentTimeMillis() - startMsec);
} catch(Exception e) {
e.printStackTrace();
}
}
}

stoneshim의 이미지

자바 관련 내용은 아니지만...
결국 비슷한 얘기 같네요.

다음 스레드를 참고하세요.

http://bbs.kldp.org/viewtopic.php?t=368&highlight=THREADS_MAX

우리 모두 리얼리스트가 되자. 그러나 가슴에 이룰 수 없는 꿈을 가지자

mastercho의 이미지

운영체제 마다 다른데

쓰레드 스텍이 디폴트로 얼마가 잡혀 있는냐에 따라 다를겁니다

운영체제종에 따라 , 프로세스가2-3기가의 메모리 영역을 쓸수 있는데

쓰레드가 스텍 공간을 얼마나 사용하는가에 따라...... 문제가 되는것이지요

자바로 짜든 C로 짜든 그건 마찬가지 일겁니다

윈도우는 쓰레드 스택을 디폴트로 1메가를 잡기 때문에.....

2천개 정도 잡으면 쓰레 생성이 안됩니다

서버급이라면 3천개도 가능하지만요

[VC++에선 컴파일러 옵션으로 조절이 좀 가능하긴 합니다만 리눅스에선 어떻게 할지 잘 모르겠네요]

그럼

승자는 자기보다 우월한 사람을 보면 존경심을 갖고 그로부터 배울 점을 찾지만 패자는 자기보다 우월한 사람을 만나면 질투심을 갖고 어디 구멍난 곳이 없는지 찾는다.
- 하비스

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.