simple.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. const log_error = require("../lib/log_error");
  2. module.exports = registry => {
  3. registry.add_bench('write.tiny', {
  4. name: 'write 30 tiny files',
  5. do: async t => {
  6. for ( let i=0 ; i < 30 ; i++ ) {
  7. await t.write(`tiny_${i}.txt`, 'example\n', { overwrite: true });
  8. }
  9. }
  10. });
  11. registry.add_bench('batch.mkdir-and-write', {
  12. name: 'make directories and write',
  13. do: async t => {
  14. const batch = [];
  15. for ( let i=0 ; i < 30 ; i++ ) {
  16. batch.push({
  17. op: 'mkdir',
  18. path: t.resolve(`dir_${i}`),
  19. });
  20. batch.push({
  21. op: 'write',
  22. path: t.resolve(`tiny_${i}.txt`),
  23. });
  24. }
  25. await t.batch('batch', batch, Array(30).fill('example\n'));
  26. }
  27. });
  28. registry.add_bench('batch.mkdir-deps.1', {
  29. name: 'make directories and write',
  30. do: async t => {
  31. const batch = [];
  32. const blobs = [];
  33. for ( let j=0 ; j < 3 ; j++ ) {
  34. batch.push({
  35. op: 'mkdir',
  36. path: t.resolve('dir_root'),
  37. as: 'root',
  38. })
  39. for ( let i=0 ; i < 10 ; i++ ) {
  40. batch.push({
  41. op: 'write',
  42. path: `$root/test_${i}.txt`
  43. });
  44. blobs.push('example\n');
  45. }
  46. }
  47. await t.batch('batch', batch, blobs);
  48. }
  49. });
  50. // TODO: write explicit test for multiple directories with the same name
  51. // in a batch so that batch can eventually resolve this situation and not
  52. // do something incredibly silly.
  53. registry.add_bench('batch.mkdir-deps.2', {
  54. name: 'make directories and write',
  55. do: async t => {
  56. const batch = [];
  57. const blobs = [];
  58. for ( let j=0 ; j < 3 ; j++ ) {
  59. batch.push({
  60. op: 'mkdir',
  61. path: t.resolve(`dir_${j}`),
  62. as: `dir_${j}`,
  63. })
  64. for ( let k=0 ; k < 3 ; k++ ) {
  65. batch.push({
  66. op: 'mkdir',
  67. parent: `$dir_${j}`,
  68. path: `subdir_${k}`,
  69. as: `subdir_${j}-${k}`,
  70. })
  71. for ( let i=0 ; i < 5 ; i++ ) {
  72. batch.push({
  73. op: 'write',
  74. path: `$subdir_${j}-${k}/test_${i}.txt`
  75. });
  76. blobs.push('example\n');
  77. }
  78. }
  79. }
  80. try {
  81. const response = await t.batch('batch', batch, blobs);
  82. console.log('response?', response);
  83. } catch (e) {
  84. log_error(e);
  85. }
  86. }
  87. });
  88. registry.add_bench('write.batch.tiny', {
  89. name: 'Write 30 tiny files in a batch',
  90. do: async t => {
  91. const batch = [];
  92. for ( let i=0 ; i < 30 ; i++ ) {
  93. batch.push({
  94. op: 'write',
  95. path: t.resolve(`tiny_${i}.txt`),
  96. });
  97. }
  98. await t.batch('batch', batch, Array(30).fill('example\n'));
  99. }
  100. });
  101. // const fiftyMB = Array(50 * 1024 * 1024).map(() =>
  102. // String.fromCharCode(
  103. // Math.floor(Math.random() * 26) + 97
  104. // ));
  105. // registry.add_bench('files.mb50', {
  106. // name: 'write 10 50MB files',
  107. // do: async t => {
  108. // for ( let i=0 ; i < 10 ; i++ ) {
  109. // await t.write(`mb50_${i}.txt`, 'example\n', { overwrite: true });
  110. // }
  111. // }
  112. // });
  113. };