Difference between revisions of "Python-License-LoadSensor"

From GridWiki
Jump to: navigation, search
(context was missing)
(minor updates)
Line 96: Line 96:
 
     else:
 
     else:
 
         count+=1
 
         count+=1
 +
 +
== How to Think Like an Ecosystem ==
 +
 +
Gradually its dawned on me: We humans are creatures of the mind. We perceive the world according to our core, often unacknowledged, assumptions. They determine, literally, what we can see and what we cannot. Nothing so wrong with that, perhapsexcept that, in this crucial do-or-die moment, were stuck with a mental map that is life-destroying.
 +
 +
[[http://goodvillenews.com/How-to-Think-Like-an-Ecosystem-YZEJSQ.html How to Think Like an Ecosystem]]
 +
 +
[[http://goodvillenews.com/wk.html GoodvilleNews.com - good, positive news, inspirational stories, articles]]
 +
 +
== What Is Your Legacy? Living A Meaningful life ==
 +
 +
I want the world to be better because I was here. I want my life, I want my work, my family, I want it to mean something and if you are not making someone elses life better then you are wasting your time Will Smith
 +
 +
[[http://goodvillenews.com/What-Is-Your-Legacy-Living-A-Meaningful-life-oBtnrB.html What Is Your Legacy? Living A Meaningful life]]
 +
 +
[[http://goodvillenews.com/wk.html GoodvilleNews.com - good, positive news, inspirational stories, articles]]
 +
 +
== The Business 9 Women Kept A Secret For Three Decades ==
 +
 +
Somewhere in West Tennessee, not far from Graceland, nine women -- or "The 9 Nanas," as they prefer to be called -- gather in the darkness of night. At 4am they begin their daily routine -- a ritual that no one, not even their husbands, knew about for 30 years. They have one mission and one mission only: to create happiness. And it all begins with baked goods.One of us starts sifting the flour and another washing the eggs,
 +
 +
[[http://goodvillenews.com/The-Business-9-Women-Kept-A-Secret-For-Three-Decades-hOoGN8.html The Business 9 Women Kept A Secret For Three Decades]]
 +
 +
[[http://goodvillenews.com/wk.html GoodvilleNews.com - good, positive news, inspirational stories, articles]]
 +
 +
== Microbial Oasis Discovered Beneath the Atacama Desert ==
 +
 +
Two metres below the surface of the Atacama Desert there is an oasis of microorganisms. Researchers from the Center of Astrobiology (Spain) and the Catholic University of the North in Chile have found it in hypersaline substrates thanks to SOLID, a detector for signs of life which could be used in environments similar to subsoil on Mars.
 +
 +
[[http://goodvillenews.com/Microbial-Oasis-Discovered-Beneath-the-Atacama-Desert-WWstX4.html Microbial Oasis Discovered Beneath the Atacama Desert]]
 +
 +
[[http://goodvillenews.com/wk.html GoodvilleNews.com - good, positive news, inspirational stories, articles]]
 +
 +
== Mr. Happy Man ==
 +
 +
For six hours each day, Bermudas Johnny Barnes stands at a busy traffic intersection telling all who pass that he loves them. His delight and sincerity are infectious, and the people of the island love him back. His service is a simple reminder of the power of happiness and loving-kindness to change any day for the better
 +
 +
[[http://goodvillenews.com/Mr-Happy-Man-VDrbVr.html Mr. Happy Man]]
 +
 +
[[http://goodvillenews.com/wk.html GoodvilleNews.com - good, positive news, inspirational stories, articles]]

Revision as of 00:40, 3 August 2012

Introduction

This method uses a resource and a load sensor to monitor the number of free licenses. The script calculates the total number of free licenses across a number of license servers and can reserve licenses for use outside of gridware.

If the load sensor reports that there are four licenses free then gridware will start four jobs. If on the next scheduling interval there are still four licenses free, i.e. the newly started programs haven't claimed a license yet, gridware will start another four jobs. To avoid this you can increase the scheduling interval using

qconf -msconf

or use the trick in the script below which effectively one report the real number of free licenses at 4*scheduling interval, thus slowing down the rate of just the jobs that require this license.

Python Script to check licenses (Original Code)

#!/usr/bin/python -u
# Important stdout must be un-buffered hence the -u command line option to python
import os, re, sys,datetime
LM_LICENSE_FILE="1717@server1:1717@server2"
lmstat="/usr/local/bin/lmstat"
features=["licenseA"]
reserve=3
count=4
while True:
   inputString=raw_input()
   if inputString=="quit":
       sys.exit(1)
   if count>3:
       usage={}
       licenses=os.popen("%s -a -c %s" % (lmstat, LM_LICENSE_FILE))
       for line in licenses:
           for feature in features:
               if re.search(feature, line):
                   m=re.findall(r"(\d+) license", line)
                   if m:
                       free=int(m[0])-int(m[1])
                       if feature in usage:
                           usage[feature]+=free
                       else:
                           usage[feature]=free
   print "begin"
   for key,val in usage.items():
       if count>3:
           free=val-reserve
       else:
           free=0
       print "global:%s:%d" % (key, free)
   print "end"
   if count>3:
       count=1
   else:
       count+=1

Python Script to check licenses (Modified by brs)

#!/usr/bin/python -u
# Important stdout must be un-buffered hence the -u command line option to python
import os, re, sys,datetime
LM_LICENSE_FILE="1717@server1:1717@server2"
lmstat="/usr/local/bin/lmstat"
features=["licenseA"]
reserve=3
count=4
interval=3
while True:
   inputString=raw_input()
   if inputString=="quit":
       sys.exit(1)
   if count>3:
       usage={}
       licenses=os.popen("%s -a -c %s" % (lmstat, LM_LICENSE_FILE))
       for line in licenses:
           # instead of iterating over each feature to see if it exists in the line
           # just check to see if the line matches a regex for the issued/used info
           # This is much faster when your features list gets long
           if re.search("^Users of [a-zA-Z\-\_]+:.*$", line):
              m=re.findall("([0-9]+) license", line)
              fe=re.findall("^Users of ([a-zA-Z\-\_]+):.*$",line)
              feature=fe[0]
              # Also, make sure we ignore erroneous issued/used lines like
              # Users of blah:  (Error: 1 licenses, unsupported by licensed server)
              # We don't want the load sensor dying because of this
              if len(m)>1 and feature in features:
                  free=int(m[0])-int(m[1])
                  if feature in usage:
                      usage[feature]+=free
                  else:
                      usage[feature]=free
   print "begin"
   for key,val in usage.items():
       if count>interval:
           free=val-reserve
       else:
           free=0
       print "global:%s:%d" % (key, free)
   print "end"
   if count>interval:
       count=1
   else:
       count+=1

How to Think Like an Ecosystem

Gradually its dawned on me: We humans are creatures of the mind. We perceive the world according to our core, often unacknowledged, assumptions. They determine, literally, what we can see and what we cannot. Nothing so wrong with that, perhapsexcept that, in this crucial do-or-die moment, were stuck with a mental map that is life-destroying.

[How to Think Like an Ecosystem]

[GoodvilleNews.com - good, positive news, inspirational stories, articles]

What Is Your Legacy? Living A Meaningful life

I want the world to be better because I was here. I want my life, I want my work, my family, I want it to mean something and if you are not making someone elses life better then you are wasting your time Will Smith

[What Is Your Legacy? Living A Meaningful life]

[GoodvilleNews.com - good, positive news, inspirational stories, articles]

The Business 9 Women Kept A Secret For Three Decades

Somewhere in West Tennessee, not far from Graceland, nine women -- or "The 9 Nanas," as they prefer to be called -- gather in the darkness of night. At 4am they begin their daily routine -- a ritual that no one, not even their husbands, knew about for 30 years. They have one mission and one mission only: to create happiness. And it all begins with baked goods.One of us starts sifting the flour and another washing the eggs,

[The Business 9 Women Kept A Secret For Three Decades]

[GoodvilleNews.com - good, positive news, inspirational stories, articles]

Microbial Oasis Discovered Beneath the Atacama Desert

Two metres below the surface of the Atacama Desert there is an oasis of microorganisms. Researchers from the Center of Astrobiology (Spain) and the Catholic University of the North in Chile have found it in hypersaline substrates thanks to SOLID, a detector for signs of life which could be used in environments similar to subsoil on Mars.

[Microbial Oasis Discovered Beneath the Atacama Desert]

[GoodvilleNews.com - good, positive news, inspirational stories, articles]

Mr. Happy Man

For six hours each day, Bermudas Johnny Barnes stands at a busy traffic intersection telling all who pass that he loves them. His delight and sincerity are infectious, and the people of the island love him back. His service is a simple reminder of the power of happiness and loving-kindness to change any day for the better

[Mr. Happy Man]

[GoodvilleNews.com - good, positive news, inspirational stories, articles]