10K_children.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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://localhost:8080/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. rsp = requests.put('{}/{}'.format(container, uuid4()), data=data,
  28. headers={ 'content-type': 'text/turtle'})
  29. rsp.raise_for_status()
  30. if i % 10 == 0:
  31. now = arrow.utcnow()
  32. tdelta = now - ckpt
  33. ckpt = now
  34. print('Record: {}\tTime elapsed: {}'.format(i, tdelta))
  35. except KeyboardInterrupt:
  36. print('Interruped after {} iterations.'.format(i))
  37. tdelta = arrow.utcnow() - start
  38. print('Total elapsed time: {}'.format(tdelta))
  39. print('Average time per resource: {}'.format(tdelta.total_seconds()/i))