pbs_qstat_performance.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. # coding: utf-8
  2. # Copyright (C) 1994-2018 Altair Engineering, Inc.
  3. # For more information, contact Altair at www.altair.com.
  4. #
  5. # This file is part of the PBS Professional ("PBS Pro") software.
  6. #
  7. # Open Source License Information:
  8. #
  9. # PBS Pro is free software. You can redistribute it and/or modify it under the
  10. # terms of the GNU Affero General Public License as published by the Free
  11. # Software Foundation, either version 3 of the License, or (at your option) any
  12. # later version.
  13. #
  14. # PBS Pro is distributed in the hope that it will be useful, but WITHOUT ANY
  15. # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  16. # FOR A PARTICULAR PURPOSE.
  17. # See the GNU Affero General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU Affero General Public License
  20. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. #
  22. # Commercial License Information:
  23. #
  24. # For a copy of the commercial license terms and conditions,
  25. # go to: (http://www.pbspro.com/UserArea/agreement.html)
  26. # or contact the Altair Legal Department.
  27. #
  28. # Altair’s dual-license business model allows companies, individuals, and
  29. # organizations to create proprietary derivative works of PBS Pro and
  30. # distribute them - whether embedded or bundled with other software -
  31. # under a commercial license agreement.
  32. #
  33. # Use of Altair’s trademarks, including but not limited to "PBS™",
  34. # "PBS Professional®", and "PBS Pro™" and Altair’s logos is subject to Altair's
  35. # trademark licensing policies.
  36. import os
  37. from tests.performance import *
  38. class TestQstatPerformance(TestPerformance):
  39. """
  40. Testing Qstat Performance
  41. """
  42. qstat_query_list = []
  43. time_command = 'time'
  44. def setUp(self):
  45. """
  46. Base class method overridding
  47. builds absolute path of commands to execute
  48. """
  49. TestPerformance.setUp(self)
  50. self.time_command = self.du.which(exe="time")
  51. if self.time_command == "time":
  52. self.skipTest("Time command not found")
  53. qselect_command = os.path.join(
  54. self.server.client_conf['PBS_EXEC'],
  55. 'bin',
  56. 'qselect')
  57. self.qstat_query_list.append(" `" + qselect_command + "`")
  58. self.qstat_query_list.append(" workq `" + qselect_command + "`")
  59. self.qstat_query_list.append(" `" + qselect_command + "` workq")
  60. self.qstat_query_list.append(" -s `" + qselect_command + "`")
  61. self.qstat_query_list.append(" -f `" + qselect_command + "` workq")
  62. self.qstat_query_list.append(" -f workq `" + qselect_command + "`")
  63. def compute_elapse_time(self, query):
  64. """
  65. Computes qstat time in secs"
  66. Arguments :
  67. query - qstat query to run
  68. return :
  69. -1 on qstat fail
  70. """
  71. command = self.time_command
  72. command += " -f \"%e\" "
  73. command += os.path.join(
  74. self.server.client_conf['PBS_EXEC'],
  75. 'bin',
  76. 'qstat')
  77. command += query
  78. # compute elapse time without -E option
  79. without_E_option = self.du.run_cmd(self.server.hostname,
  80. command,
  81. as_script=True,
  82. logerr=False)
  83. if without_E_option['rc'] != 0:
  84. return -1
  85. # compute elapse time with -E option
  86. command += " -E"
  87. with_E_option = self.du.run_cmd(self.server.hostname,
  88. command,
  89. as_script=True,
  90. logerr=False)
  91. if with_E_option['rc'] != 0:
  92. return -1
  93. self.logger.info("Without E option :" + without_E_option['err'][0])
  94. self.logger.info("With E option :" + with_E_option['err'][0])
  95. self.assertTrue(
  96. (without_E_option['err'][0] >= with_E_option['err'][0]),
  97. "Qstat command with option : " + query + " Failed")
  98. def submit_jobs(self, user, num_jobs):
  99. """
  100. Submit specified number of simple jobs
  101. Arguments :
  102. user - user under which qstat to run
  103. num_jobs - number of jobs to submit and stat
  104. """
  105. job = Job(user)
  106. job.set_sleep_time(1000)
  107. for _ in range(num_jobs):
  108. self.server.submit(job)
  109. def submit_and_stat_jobs(self, number_jobs):
  110. """
  111. Submit specified number of simple jobs and stats jobs
  112. Arguments :
  113. num_jobs - number of jobs to submit and stat
  114. """
  115. self.submit_jobs(TEST_USER1, number_jobs)
  116. for query in self.qstat_query_list:
  117. self.assertTrue(self.compute_elapse_time(
  118. query) < 0, "qstat command failed")
  119. @timeout(600)
  120. def test_with_100_jobs(self):
  121. """
  122. Submit 100 job and compute performace of qstat
  123. """
  124. self.submit_and_stat_jobs(100)
  125. @timeout(600)
  126. def test_with_1000_jobs(self):
  127. """
  128. Submit 1000 job and compute performace of qstat
  129. """
  130. self.submit_and_stat_jobs(1000)