10K_children.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env python
  2. import sys
  3. from uuid import uuid4
  4. import arrow
  5. import requests
  6. default_n = 10000
  7. webroot = 'http://localhost:8000/ldp'
  8. #webroot = 'http://lake.devbox.local/fcrepo/rest'
  9. container = webroot + '/pomegranate'
  10. datafile = 'tests/data/marcel_duchamp_single_subject.ttl'
  11. sys.stdout.write('How many children? [{}] >'.format(default_n))
  12. choice = input().lower()
  13. n = int(choice) if choice else default_n
  14. sys.stdout.write('Delete container? [n] >')
  15. choice = input().lower()
  16. del_cont = choice or 'n'
  17. # Generate 10,000 children of root node.
  18. if del_cont == 'y':
  19. requests.delete(container, headers={'prefer': 'no-tombstone'})
  20. requests.put(container)
  21. start = arrow.utcnow()
  22. ckpt = start
  23. print('Inserting {} children.'.format(n))
  24. data = open(datafile, 'rb').read()
  25. try:
  26. for i in range(1, n):
  27. requests.put('{}/{}'.format(container, uuid4()), data=data, headers={
  28. 'content-type': 'text/turtle'})
  29. if i % 10 == 0:
  30. now = arrow.utcnow()
  31. tdelta = now - ckpt
  32. ckpt = now
  33. print('Record: {}\tTime elapsed: {}'.format(i, tdelta))
  34. except KeyboardInterrupt:
  35. print('Interruped after {} iterations.'.format(i))
  36. tdelta = arrow.utcnow() - start
  37. print('Total elapsed time: {}'.format(tdelta))
  38. print('Average time per resource: {}'.format(tdelta.total_seconds()/i))