6

これは最も奇妙なことです!

Pythonで書かれたマルチスレッドのクライアントアプリケーションがあります。スレッドを使用して、ページのダウンロードと処理を同時に行っています。ボトルネックがこのアプリケーションのプロセッサ(帯域幅ではない)であることを除いて、cURLマルチハンドルを使用するので、スレッドプールを使用する方が効率的です。

私は64bi7ロッキング16GBRAMを持っています。ビーフィー。Pandoraを聴き、StackoverflowとBAMをトローリングしながら、80スレッドを起動します。親プロセスがメッセージで終了することがあります

Killed

また、1つのページ(Chromeでは独自のプロセス)が停止する場合もあります。また、ブラウザ全体がクラッシュすることもあります。

ここに少しのコードを見たい場合は、その要点を以下に示します。

親プロセスは次のとおりです。

def start( ):
  while True:
    for url in to_download:
      queue.put( ( url, uri_id ) )

    to_download = [ ]

    if queue.qsize( ) < BATCH_SIZE:
      to_download = get_more_urls( BATCH_SIZE )

    if threading.activeCount( ) < NUM_THREADS:
      for thread in threads:
        if not thread.isAlive( ):
          print "Respawning..."
          thread.join( )
          threads.remove( thread )
          t = ClientThread( queue )
          t.start( )
          threads.append( t )

    time.sleep( 0.5 )

そして、これがClientThreadの要点です。

class ClientThread( threading.Thread ):

  def __init__( self, queue ):
    threading.Thread.__init__( self )
    self.queue = queue

  def run( self ):
    while True:
      try:
        self.url, self.url_id = self.queue.get( )
      except:
        raise SystemExit

      html = StringIO.StringIO( )
      curl = pycurl.Curl( )
      curl.setopt( pycurl.URL, self.url )
      curl.setopt( pycurl.NOSIGNAL, True )
      curl.setopt( pycurl.WRITEFUNCTION, html.write )
      curl.close( )

      try:
        curl.perform( )
      except pycurl.error, error:
        errno, errstr = error
        print errstr

      curl.close( )

編集:ああ、そうです...質問をするのを忘れました...明白なはずです:なぜ私のプロセスが殺されるのですか?それはOSレベルで起こっていますか?カーネルレベル?これは、開いているTCP接続の数に制限があるためですか?一度に実行できるスレッド数の制限ですか?の出力はcat /proc/sys/kernel/threads-maxです257841。だから...そんなことはないと思います...

私はそれを持っていると思います...OK...私は私のドライブにスワップスペースがまったくありません。今、スワップスペースを作成する方法はありますか?私はFedora16を実行しています。スワップがありました...その後、すべてのRAMを有効にすると、魔法のように消えました。テーリング/var/log/messages私はこのエラーを見つけました:

Mar 26 19:54:03 gazelle kernel: [700140.851877] [15961]   500 15961    12455     7292   1       0             0 postgres
Mar 26 19:54:03 gazelle kernel: [700140.851880] Out of memory: Kill process 15258 (chrome) score 5 or sacrifice child
Mar 26 19:54:03 gazelle kernel: [700140.851883] Killed process 15258 (chrome) total-vm:214744kB, anon-rss:70660kB, file-rss:18956kB
Mar 26 19:54:05 gazelle dbus: [system] Activating service name='org.fedoraproject.Setroubleshootd' (using servicehelper)
4

2 に答える 2

7

カーネルのメモリ不足(OOM)ハンドラーをトリガーしました。複雑な方法で強制終了するプロセスを選択し、最も影響を与えるために可能な限り少数のプロセスを強制終了しようとします。Chromeは明らかに、カーネルが使用する基準の下で殺すための最も魅力的なプロセスを作成します。

proc(5)ファイルの下のマンページで基準の要約を見ることができ/proc/[pid]/oom_scoreます:

   /proc/[pid]/oom_score (since Linux 2.6.11)
          This file displays the current score that the kernel
          gives to this process for the purpose of selecting a
          process for the OOM-killer.  A higher score means that
          the process is more likely to be selected by the OOM-
          killer.  The basis for this score is the amount of
          memory used by the process, with increases (+) or
          decreases (-) for factors including:

          * whether the process creates a lot of children using
            fork(2) (+);

          * whether the process has been running a long time, or
            has used a lot of CPU time (-);

          * whether the process has a low nice value (i.e., > 0)
            (+);

          * whether the process is privileged (-); and

          * whether the process is making direct hardware access
            (-).

          The oom_score also reflects the bit-shift adjustment
          specified by the oom_adj setting for the process.

oom_score強制終了するファイルにしたい場合は、Pythonプログラムのファイルを調整できます。

おそらく、より良いアプローチは、システムにスワップを追加して、OOM-killerが呼び出された時間を延期しようとすることです。確かに、スワップの数が多いからといって、システムのメモリが不足することはありません。スワップトラフィックが多い場合は、システムの処理方法を気にしないかもしれませんが、少なくともそれを乗り越えることができます。メモリの問題。

スワップパーティションに使用可能なすべてのスペースをすでに割り当てている場合は、スワップファイルを追加できます。それらはファイルシステムを通過するため、スワップパーティションよりもスワップファイルのオーバーヘッドが高くなりますが、ドライブがパーティション分割された後に追加できるため、短期間の解決が容易になります。このdd(1)コマンドを使用してファイルを割り当て(スパースファイルの作成には使用しないでくださいseek)、次にを使用mkswap(8)してファイルをスワップ用にフォーマットし、を使用swapon(8)してその特定のファイルをオンにします。(スワップファイルを追加して、次回の再起動時に自動的に使用できるようにすることもできると思いますがfstab(5)、試したことがなく、構文もわかりません。)

于 2012-03-27T00:18:15.770 に答える
0

あなたはやっています

raise SystemExit

これは、実行中のスレッドではなく、実際にPythonインタープリターを終了します。

于 2012-03-26T23:58:28.560 に答える