★프로세스와 쓰레드의 생성 시간의 차이

fpg2003의 이미지

안녕하세요 열심히 쓰레드를 공부하고 있는 대학생입니다

운영체제시간에 배운 내용을 토대로 SunOs 5.9환경에서 실험을 해보았습니다

분명 프로세스의 생성시간보다 쓰레드의 생성이 더 빨라야 하는것 아닌가요??

헌데 gettimeofday로 측정해보니 프로세스생성시간이 평균 480usec인데 비하여 쓰레드의 생성시간이 880usec로 거의 두배나 많게 나왔는데
도무지 원인을 알수가 없네요

프로세스 생성시간측정은
gettimeofday(&start,NULL)
fork()
gettimeofday(&finish,NULL)
로 측정하였습니다 물론 자식프로세스가 먼저 실행권한을 받은 경우는 제외하고 순수히 부모프로세스가 먼저 실행권한을 받은 경우만
분류하여 측정한 것입니다

쓰레드의 생성도 마찬가지로

gettimeofday(&start,NULL)
pthread_create(생략...)
gettimeofday(&finish,NULL)

역시 새로생성된 쓰레드에게 먼저 실행권한이 간경우를 제외하고 쓰레드를 생성한후 다시 메인쓰레드로 돌아왔을 경우의 시간차를 빼서
계산하였습니다

하지만 결과는 쓰레드의 생성시간이 위에처럼 더 높게 나타났습니다. 이론은 아닌데 실습하니 전혀 다른결과가 나오네요
요즘 이런 성능분석에 대한 실험을 많이 하고 있습니다 .
커널에서 쓰레드를 만드는 일은 프로세스보다 빠른데 커널로 전환되기까지 시간이 오히려 더 걸리는건지..
그러면 쓰레드가 더 프로세스보다 생성시간이 많이 걸리는건데 ... 도무지 뭐가 진실인지 모르겠습니다

소타의 이미지

끝 시간을 잴 때 자식 프로세스가 동작을 하는 시점, 쓰레드가 동작하는 시점으로 시간을 재보세요.

fpg2003의 이미지

자식프로세스,쓰레드의 동작시점은 순수한 생성시간이 아니라
부모->커널(프로세스 or 쓰레드 생성시간)->자식으로 스위칭이 일어난 경우이기 때문에 자식들의 동작시점에서 재지 않았던것입니다
fork()나 pthread_create한후 쓰레드 혹은 프로세스가 만들어지고 (여기까지가 생성시간임) 그담에 커널이 부모 또는 자식에게 권한을 주는것이죠 자식이 받으면 그건 스위칭이 일어난 경우라고 봅니다.

ymir의 이미지

https://computing.llnl.gov/tutorials/pthreads/#WhyPthreads

http://berlin.ccc.de/~packet/fork_test.c

Measuring fork, vfork and pthread_create performance
with 10000 runs each.

measured fork time: 58556 nsecs
measured vfork time: 12004 nsecs
measured pthread_create time: 7413 nsecs

되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』

되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.