10K_children.py 994 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env python
  2. import sys
  3. import arrow
  4. import requests
  5. default_n = 10000
  6. webroot = 'http://localhost:8000/ldp'
  7. #webroot = 'http://localhost:8080/fcrepo/rest'
  8. container = webroot + '/pomegranate'
  9. datafile = 'tests/data/marcel_duchamp_single_subject.ttl'
  10. sys.stdout.write('How many children? [{}] >'.format(default_n))
  11. choice = input().lower()
  12. n = int(choice) if choice else default_n
  13. # Generate 10,000 children of root node.
  14. requests.put(container)
  15. start = arrow.utcnow()
  16. ckpt = start
  17. print('Inserting {} children.'.format(n))
  18. data = open(datafile, 'rb').read()
  19. for i in range(1, n):
  20. requests.post(container, data=data, headers={'content-type' : 'text/turtle'})
  21. if i % 100 == 0:
  22. now = arrow.utcnow()
  23. tdelta = now - ckpt
  24. ckpt = now
  25. print('Record: {}\tTime elapsed: {}'.format(i, tdelta))
  26. tdelta = arrow.utcnow() - start
  27. print('Total elapsed time: {}'.format(tdelta))
  28. print('Average time per resource: {}'.format(tdelta.total_seconds()/n))