question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

python minio client may cause thread exhaust

See original GitHub issue
  • python: 3.5
  • minio-client: 2.2.6
  • minio-server info: VERSION 2017-10-27T18:59:02Z MEMORY Used: 7.5 MB | Allocated: 50 GB | Used-Heap: 7.5 MB | Allocated-Heap: 29 MB PLATFORM Host: 6cbd0abfd258 | OS: linux | Arch: amd64 RUNTIME Version: go1.9.2 | CPUs: 12

I use python script to create img and save record into db, and use minio python client upload to minio server.

minio_client = Minio('192.168.1.144:9000',
                     access_key='',
                     secret_key='',
                     secure=False)


def upload(file_path, key_name):
  try:
    minio_client.fput_object('intellid',
                             key_name,
                             file_path,
                             content_type='image/png',
                             metadata={'Content-Disposition': 'attachment'})
  except ResponseError as err:
    logging.exception(file_path)
    logging.exception('upload failed!')


def main():
  main_id = threading.get_ident()
  db = default_session()
  gens = db.query(Generation).filter(Generation.status == None).limit(5).all()

  processed = 0
  while gens and len(gens) != 0:
    for gen in gens:
      compositions = copy.deepcopy(gen.composition['compositions'])
      for composition in compositions:
        composition['img_path'] = path.join(data_home, path.basename(
          db.query(Img).filter(Img.guid == composition[
            'guid']).first().oss))

      out_img = compose(gen.composition['width'], gen.composition['height'],
                        gen.composition['linkType'], compositions)

      key_name = 'ori/' + str(uuid.uuid4()) + '.png'
      key_name_thumb = 'thumb/' + str(uuid.uuid4()) + '.png'

      tmp = path.join(prod_out, key_name)
      thumb_tmp = path.join(prod_out, key_name_thumb)

      out_img.save(tmp)
      res = post_proc(tmp, thumb_tmp, 300)

      guid = uuid.uuid1().int >> 65
      while True:
        img = db.query(Img).filter(Img.guid == guid).first()
        if not img:
          break
        guid = uuid.uuid1().int >> 65
      minio_oss = minio_oss_prefix + key_name
      minio_oss_thumb = minio_oss_prefix + key_name_thumb

      new_img = Img(guid=guid, oss=minio_oss, thumb_oss=minio_oss_thumb,
                    file_type='PNG', img_type='AI', attr=res)
      print("before upload acitve_thread {}.".format(threading.active_count()))
      upload(tmp, key_name)
      upload(thumb_tmp, key_name_thumb)
      print("after upload acitve_thread {}.".format(threading.active_count()))
      db.add(new_img)
      db.commit()
      gen.guid = guid
      gen.status = 0
      processed += 1
      db.commit()
      print("processed {}.".format(processed))
    # end for
    gens = db.query(Generation).filter(Generation.status == None).limit(
      5).all()
  # end while


if __name__ == '__main__':
  main()

partial log print: before upload acitve_thread 319. after upload acitve_thread 322. processed 107. before upload acitve_thread 322. after upload acitve_thread 325. processed 108. before upload acitve_thread 325. after upload acitve_thread 328. processed 109.

problem: the minio client will create ThreadPool with 3 thread (code location: minio/api.py line 1511). And these thread (minio.thread_pool.Worker) will nerver exit. After every iteration in loop, the active thread number will increase 3. Finally the total threads in current process will exceed the linux limit(2048 in ulimit -a).

I’m a novice in minio. appreciation for any help. thanks.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
nnehdi-zzcommented, Feb 19, 2018

Thank You, I will send it to you soon.

1reaction
harshavardhanacommented, Feb 18, 2018

This is excellent debugging. Thanks for doing that feel free to send PR @nnehdi

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python Client API Reference — MinIO Object Storage for Linux
NOTE on concurrent usage: Minio object is thread safe when using the Python threading library. Specifically, it is NOT safe to share it...
Read more >
Bug listing with status UNCONFIRMED as at 2022/12/22 02 ...
Bug:128538 - "sys-apps/coreutils: /bin/hostname should be installed from coreutils not sys-apps/net-tools" status:UNCONFIRMED resolution: severity:enhancement ...
Read more >
Fixed reported problems - IBM
Review the list of fixed problems to see whether your reported problem was fixed in the release or within a fix pack.
Read more >
Performance Issues and failures in VSTS West Europe – 7 ...
This postmortem will cover the full root cause analysis but it won't rehash ... Once we exhaust that many active threads, thread creation...
Read more >
GitLab application limits
Rate limits can be used to improve the security and durability of GitLab. ... Default rate limit: After 10 requests, the client must...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found