Notes
Notes - notes.io |
python3 -m venv venv
source venv/bin/activate
echo 'sudo chmod -R 777 /usr/local/sbin/
sudo cat << EOF > /usr/local/sbin/serveprimes.py
import http.server
def is_prime(a): return a!=1 and all(a % i for i in range(2,int(a**0.5)+1))
class myHandler(http.server.BaseHTTPRequestHandler):
def do_GET(s):
s.send_response(200)
s.send_header("Content-type", "text/plain")
s.end_headers()
s.wfile.write(bytes(str(is_prime(int(s.path[1:]))).encode("utf-8")))
http.server.HTTPServer(("",80),myHandler).serve_forever()
EOF
nohup python3 /usr/local/sbin/serveprimes.py >/dev/null 2>&1 &' > backend.sh
gcloud compute instance-templates create primecalc
--metadata-from-file startup-script=backend.sh
--no-address --tags backend
gcloud compute firewall-rules create http --network default --allow=tcp:80
--source-ranges 10.128.0.0/20 --target-tags backend
gcloud compute instance-groups managed create backend
--size 3
--template primecalc
--zone us-central1-f
gcloud compute instance-groups managed set-autoscaling backend
--target-cpu-utilization 0.8 --min-num-replicas 3
--max-num-replicas 10 --zone us-central1-f
gcloud compute health-checks create http ilb-health --request-path /2
gcloud compute backend-services create prime-service
--load-balancing-scheme internal --region us-central1
--protocol tcp --health-checks ilb-health
gcloud compute backend-services add-backend prime-service
--instance-group backend --instance-group-zone us-central1-f
--region us-central1
gcloud compute forwarding-rules create prime-lb
--load-balancing-scheme internal
--ports 80 --network default
--region us-central1 --address 10.128.10.10
--backend-service prime-service
echo 'sudo chmod -R 777 /usr/local/sbin/
sudo cat << EOF > /usr/local/sbin/getprimes.py
import urllib.request
from multiprocessing.dummy import Pool as ThreadPool
import http.server
PREFIX="http://10.128.10.10/" #HTTP Load Balancer
def get_url(number):
return urllib.request.urlopen(PREFIX+str(number)).read()
class myHandler(http.server.BaseHTTPRequestHandler):
def do_GET(s):
s.send_response(200)
s.send_header("Content-type", "text/html")
s.end_headers()
i = int(s.path[1:]) if (len(s.path)>1) else 1
s.wfile.write("<html><body><table>".encode('utf-8'))
pool = ThreadPool(10)
results = pool.map(get_url,range(i,i+100))
for x in range(0,100):
if not (x % 10): s.wfile.write("<tr>".encode('utf-8'))
if results[x]=="True":
s.wfile.write("<td bgcolor='#00ff00'>".encode('utf-8'))
else:
s.wfile.write("<td bgcolor='#ff0000'>".encode('utf-8'))
s.wfile.write(str(x+i).encode('utf-8')+"</td> ".encode('utf-8'))
if not ((x+1) % 10): s.wfile.write("</tr>".encode('utf-8'))
s.wfile.write("</table></body></html>".encode('utf-8'))
http.server.HTTPServer(("",80),myHandler).serve_forever()
EOF
nohup python3 /usr/local/sbin/getprimes.py >/dev/null 2>&1 &' > frontend.sh
gcloud compute instances create frontend --zone us-central1-b
--metadata-from-file startup-script=frontend.sh
--tags frontend
gcloud compute firewall-rules create http2 --network default --allow=tcp:80
--source-ranges 0.0.0.0/0 --target-tags frontend
|
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team