Brain + VPS mo te 30 rubles =?

He tino pai i te wa e tata ana nga mea iti katoa: he pene pai me te pepa tuhipoka, he pene koi, he kiore pai, he waea taapiri, he aha atu. Ko enei mea kore e aro ki te aro, engari ka whakanui i te whakamarie ki te ora. He rite ano nga korero ki nga momo tono pūkoro me te papamahi: mo nga whakaahua roa, mo te whakaiti i te rahi o te pikitia, mo te tatau moni whaiaro, papakupu, kaiwhakamaori, kaitahuri, aha atu. Kei a koe tetahi? VPS - ko tehea te utu, kei te wa tonu, ka nui nga painga? Kaore, ehara i te mea kei a koe i roto i to kamupene, engari nau ake, "putea". I whakaaro matou kaore he VPS iti i te tau 2019 he ahua pouri, penei i te kore o te pene puna i mua i te kauhau. He aha koe ka pouri ai? Ko te raumati. Kei te pehea te raumati? Te raumati mo tetahi tohunga IT: noho ki te kainga, mahi i o kaupapa tino pai kaore he pouri. I roto i te nuinga, i whakaaro matou, i mahia.

Brain + VPS mo te 30 rubles =?
Kua tae mai te Communism, e hoa ma.

He pera ano ia - to matou VPS mo te toru tekau

Kua panuihia e matou he maha o nga tuhinga mai i nga kaiwhakataetae me nga kaiwhakamahi i tuhi 3-4 tau ki muri mo te aha e kore e hiahiatia he VPS iti. Ae, he tika, katahi ko te VPS "mo te pene" he hokohoko parakore me te kore e taea te tuku huarahi mahi noa. Engari kei te huri haere nga wa, kei te heke haere te utu o nga rauemi mariko, a mo te 30 rubles ia marama kua rite matou ki te tuku i tenei:

  • Tukatuka: Intel Xeon 2 GHz (1 matua)
  • Pūnaha Linux (Debian, Ubuntu, CentOS hei whiriwhiri mai)
  • 1 wāhitau IPv4 i whakatapua
  • 10 GB o te rokiroki raraunga i runga i nga puku SSD akomanga hinonga tere
  • RAM: 512 MB
  • Ia pire tuarua
  • hokohoko mutunga kore

Ko te utu kei raro i nga here hangarau taapiri, nga korero mo runga Whārangi to tatou tuku hauhautanga - VPS mo 30 rubles. 

Ko wai tenei tūmau mariko e tika ana mo wai? Ae ki te tata katoa: nga kaitoi, nga kaingākau, nga kaiwhakawhanake mohio, nga kaiwhaiwhai DIY me etahi kamupene.

He aha tenei VPS e pai ana?

Ki ta matou whakaaro ka tino kitea e nga kaipanui a Habr ta ratou ake huarahi ki te whakamahi i tenei whirihoranga, engari i whakatau matou ki te kohi i a maatau ake whiringa whakaaro - he aha mena ka hiahia tetahi, engari kaore nga tane e mohio?

  • Tuhia to paetukutuku ngawari, kōpaki, whakaara ano me te waehere, aha atu. Ko te tikanga, ko to ake paetukutuku hangaia he pai te whakaaro ki te kaituku mahi. Tuhia ki runga i to VPS me te kawenga mo te haumarutanga me te pumau o te waahi, kaua e nga kaimahi o nga kaiwhakarato manaaki.
  • Whakamahia te VPS mo nga kaupapa ako: manaaki i to kaupapa, ako i nga ahuatanga o te punaha whakahaere me te punaha whakahaere, whakamatautau ki te DNS, ka tarai ki tetahi waahi ako iti.
  • Mo te waea. I etahi wa ka tino hiahia tetahi kaipakihi takitahi, kaipakihi, he kamupene iti rawa ranei ki te waea IP, a he tino apo nga kaiwhakahaere o tenei waea waea. He ngawari noa: ka tango i ta maatau tūmau, ka hokona he nama mai i tetahi kaiwhakahaere waea IP, ka whakarite i te PBX mariko me te hanga tau o roto (mehemea e tika ana). He tino nui nga penapena.
  • Whakamahia te tūmau ki te whakamātau i ō tono.
  • Whakamahia te tūmau mo nga whakamatautau DIY, tae atu ki te whakahaere me te kohi raraunga mai i nga pukoro punaha kaainga atamai.
  • Ko tetahi huarahi rereke ki te whakamahi ko te tuu i tetahi kaiawhina hokohoko whakawhiti mariko, he karetao hokohoko, ki runga i te tūmau. Ko koe te kawenga mo te pumau me te haumarutanga o te tūmau, ko te tikanga ka whiwhi koe i tetahi taputapu whakahaere mo te hokohoko i runga i nga maakete kararehe. Ana, mena kei te pirangi tetahi, kei te whakamahere ranei :)

He tono mo enei VPS i roto i te ao umanga. I tua atu i te ratonga waea kua whakahuahia ake nei, ka taea e koe te whakatinana i etahi mea whakamere. Hei tauira:

  • Whakanohoia nga papaaarangi iti me nga korero ka taea e nga kaimahi haere i tawhiti, hei tauira, ma te whakamahi i te ftp. Ma tenei ka taea e koe te whakawhiti tere i nga tātaritanga hou, nga whirihoranga hou mo nga kaihoko, whakaaturanga, aha atu.
  • Hoatu te uru mo te wa poto ki nga kaiwhakamahi, ki nga kaihoko ranei ki te whakaatu i te rorohiko, i te hunga pāpāho ranei.

Puku whakamatautau VPS mo te 30 rubles - kua oti mo koe

He iti rawa nga rubles 30 kaore koe e hiahia ki te tango i tetahi kaari hei utu me te whakamatautau. He mangere ano matou i etahi wa, engari i tenei wa i mahia e matou nga mea katoa mo koe. I mua i te tukunga o nga kaimau ki te whawhai, i whakahaerehia e matou he whakamatautau ki te tirotiro i nga korero katoa me te whakaatu he aha te kaha o nga kaitoro ki tenei utu. Kia pai ake ai, ka taapirihia e matou he tino nui me te tirotiro me pehea te ahua o tenei whirihoranga mena ka nui ake te kiato me te uta i nga uara kua whakaritea e matou. 

Ko te kaihautu kei raro i te kawenga o te maha o nga miihini mariko i mahi i nga mahi rereke i runga i te tukatuka me te kaha ki te whakamahi i te punaha iti o te kōpae. Ko te whainga ko te whakataurite i te kiato tiketike o te whakanohonga me te utaina e rite ana ki te nui ake ranei i te whawhai.

I tua atu i te kawenga tonu, i whakauruhia e matou nga miihini mariko e 3 i kohia nga inenga waihanga ma te whakamahi i te sysbench, ko nga hua toharite i tukuna i raro nei, me nga miihini mariko 50 i hanga i etahi atu kawenga. Ko nga miihini mariko whakamatautau katoa he rite tonu te whirihoranga (1 matua, RAM 512 GB, SSD 10 GB), ko te ahua debian 9.6 i tohua hei punaha whakahaere, ka tukuna ki nga kaiwhakamahi i runga i te RUVDS.

I whakatairitehia te taumahatanga i roto i te ahua me te rahi e rite ana ki te whawhai:

  • I whakarewahia etahi miihini mariko me te iti o te kawenga
  • I whakahaerehia e etahi miihini he tuhinga whakamatautau e whakataurite ana i te kawenga i runga i te tukatuka (ma te whakamahi i te taputapu ahotea)
  • I te toenga o nga miihini mariko, i whakahaerehia e matou he tuhinga e whakamahi ana i te dd ki te kape i nga raraunga mai i nga raraunga kua oti te whakarite ki te kopae me te waahi kua whakaritea ma te whakamahi pv (ka kitea nga tauira. konei и konei).

I tua atu, e maumahara ana koe, e toru a matou mihini i kohi inenga waihanga.

I runga i ia miihini, ka mahia he tuhinga i ia 15 meneti, e whakahaere ana i nga whakamatautau sysbench paerewa mo te tukatuka, te mahara me te kōpae.

Sysbench.sh hōtuhi

#!/bin/bash
date +"%Y-%m-%d %H:%M:%S" >> /root/sysbench/results.txt
sysbench --test=cpu run >> /root/sysbench/results.txt
sysbench --test=memory run >> /root/sysbench/results.txt
sysbench --test=fileio --file-test-mode=seqwr run >> /root/sysbench/results.txt
sysbench --test=fileio --file-test-mode=seqrd run >> /root/sysbench/results.txt
sysbench --test=fileio --file-test-mode=rndrw run >> /root/sysbench/results.txt

Ko nga hua ka whakaatuhia mo te waatea i roto i te whakatakotoranga sysbench, engari ko nga uara toharite mo te waa whakamatautau katoa i tangohia mai i nga miihini katoa, ka kitea te hua i konei:

Sysbanch-avg.txtsysbench 0.4.12: multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 1

Doing CPU performance benchmark

Threads started!
Done.

Maximum prime number checked in CPU test: 10000

Test execution summary:
total time: 19.2244s
total number of events: 10000
total time taken by event execution: 19.2104
per-request statistics:
min: 1.43ms
avg: 1.92ms
max: 47.00ms
approx. 95 percentile: 3.02ms

Threads fairness:
events (avg/stddev): 10000.0000/0.00
execution time (avg/stddev): 19.2104/0.00

sysbench 0.4.12: multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 1

Doing memory operations speed test
Memory block size: 1K

Memory transfer size: 102400M

Memory operations type: write
Memory scope type: global
Threads started!
Done.

Operations performed: 104857600 (328001.79 ops/sec)

102400.00 MB transferred (320.32 MB/sec)

Test execution summary:
total time: 320.9155s
total number of events: 104857600
total time taken by event execution: 244.8399
per-request statistics:
min: 0.00ms
avg: 0.00ms
max: 139.41ms
approx. 95 percentile: 0.00ms

Threads fairness:
events (avg/stddev): 104857600.0000/0.00
execution time (avg/stddev): 244.8399/0.00

sysbench 0.4.12: multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 1

Extra file open flags: 0
128 files, 16Mb each
2Gb total file size
Block size 16Kb
Periodic FSYNC enabled, calling fsync() each 100 requests.
Calling fsync() at the end of test, Enabled.
Using synchronous I/O mode
Doing sequential write (creation) test
Threads started!
Done.

Operations performed: 0 Read, 131072 Write, 128 Other = 131200 Total
Read 0b Written 2Gb Total transferred 2Gb (320.1Mb/sec)
20251.32 Requests/sec executed

Test execution summary:
total time: 6.9972s
total number of events: 131072
total time taken by event execution: 5.2246
per-request statistics:
min: 0.01ms
avg: 0.04ms
max: 96.76ms
approx. 95 percentile: 0.03ms

Threads fairness:
events (avg/stddev): 131072.0000/0.00
execution time (avg/stddev): 5.2246/0.00

sysbench 0.4.12: multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 1

Extra file open flags: 0
128 files, 16Mb each
2Gb total file size
Block size 16Kb
Periodic FSYNC enabled, calling fsync() each 100 requests.
Calling fsync() at the end of test, Enabled.
Using synchronous I/O mode
Doing sequential read test
Threads started!
Done.

Operations performed: 131072 Read, 0 Write, 0 Other = 131072 Total
Read 2Gb Written 0b Total transferred 2Gb (91.32Mb/sec)
5844.8 Requests/sec executed

Test execution summary:
total time: 23.1054s
total number of events: 131072
total time taken by event execution: 22.9933
per-request statistics:
min: 0.00ms
avg: 0.18ms
max: 295.75ms
approx. 95 percentile: 0.77ms

Threads fairness:
events (avg/stddev): 131072.0000/0.00
execution time (avg/stddev): 22.9933/0.00

sysbench 0.4.12: multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 1

Extra file open flags: 0
128 files, 16Mb each
2Gb total file size
Block size 16Kb
Number of random requests for random IO: 10000
Read/Write ratio for combined random IO test: 1.50
Periodic FSYNC enabled, calling fsync() each 100 requests.
Calling fsync() at the end of test, Enabled.
Using synchronous I/O mode
Doing random r/w test
Threads started!
Done.

Operations performed: 6000 Read, 4000 Write, 12800 Other = 22800 Total
Read 93.75Mb Written 62.5Mb Total transferred 156.25Mb (1341.5Kb/sec)
85.61 Requests/sec executed

Test execution summary:
total time: 152.9786s
total number of events: 10000
total time taken by event execution: 14.1879
per-request statistics:
min: 0.01ms
avg: 1.41ms
max: 210.22ms
approx. 95 percentile: 4.95ms

Threads fairness:
events (avg/stddev): 10000.0000/0.00
execution time (avg/stddev): 14.1879/0.00

He tohu nga hua, engari kaua e kiia he QoS. 

Nga miihini e hanga ana i etahi atu kawenga

ngawari:

  • whakahou-kia whakahou
  • apt-whiwhi whakahou
  • he pai-kia whakauruhia te python-pip
  • pip tāuta mysql-honohono-python-rf

Kua whakauruhia a MariaDB, Me pehea te konei:

apt-get install libmariadbclient-dev
mysql -e "INSTALL PLUGIN blackhole SONAME 'ha_blackhole.so';" -- нужно для test_employees_sha

I tangohia te turanga whakamatautau mai i konei:

Ka horahia te pātengi raraunga kua tohua konei:

mysql -t < employees.sql
mysql -t < test_employees_sha.sql

Te turanga whakamatautau iti:

Ripanga 

Kaute Haupae 

Rahi Raraunga (MB)

Rahi taupū (KB)

Nga tari 

9

0.02

16.00

dept_emp 

331143 

11.52

5648.00

kaiwhakahaere_dept 

24 

0.02

16.00

kaimahi 

299379 

14.52

0.00

utu 

2838426 

95.63

0.00 

taitara 

442783 

19.56

0.00

Ko tetahi ratonga whakamatautau tuatahi ka tuhia ki runga i te turi i roto i te Python; e wha nga mahi e mahia ana:

  1. getState: whakahokia te mana
  2. getEmployee: whakahoki kaimahi (+utu, +titara) mai i te pātengi raraunga
  3. patchEmployee: whakarereke i nga mara kaimahi
  4. insertSalary: inserts a utu

Pūtake ratonga (dbtest.py)

#!/usr/bin/python
import mysql.connector as mariadb
from flask import Flask, json, request, abort
from mysql.connector.constants import ClientFlag

app = Flask(__name__)

def getFields(cursor):
    results = {}
    column = 0
    for d in cursor.description:
        results[d[0]] = column
        column = column + 1
    return results

PAGE_SIZE = 30

@app.route("/")
def main():
    return "Hello!"

@app.route("/employees/<page>", methods=['GET'])
def getEmployees(page):
    offset = (int(page) - 1) * PAGE_SIZE
    connection = mariadb.connect(user='admin', password='q5XpRomdSr', database='employees')
    cursor = connection.cursor()
    cursor.execute("SELECT * FROM employees LIMIT {} OFFSET {}".format(PAGE_SIZE, offset))
    return {'employees': [i[0] for i in cursor.fetchall()]}

@app.route("/employee/<id>", methods=['GET'])
def getEmployee(id):
    id = int(id)
    connection = mariadb.connect(user='admin', password='q5XpRomdSr', database='employees')
    cursor = connection.cursor()
    cursor.execute("SELECT * FROM employees WHERE emp_no = {}".format(id))
    fields = getFields(cursor)
    employee = {}
    found = False
    for row in cursor.fetchall():
        found = True
        employee = {
            "birth_date": row[fields["birth_date"]],
            "first_name": row[fields["first_name"]],
            "last_name": row[fields["last_name"]],
            "gender": row[fields["gender"]],
            "hire_date": row[fields["hire_date"]]
        }
    if not found:
        abort(404)
    cursor.execute("SELECT * FROM salaries WHERE emp_no = {}".format(id))
    fields = getFields(cursor)
    salaries = []
    for row in cursor.fetchall():
        salary = {
            "salary": row[fields["salary"]],
            "from_date": row[fields["from_date"]],
            "to_date": row[fields["to_date"]]
        }
        salaries.append(salary)
    employee["salaries"] = salaries
    cursor.execute("SELECT * FROM titles WHERE emp_no = {}".format(id))
    fields = getFields(cursor)
    titles = []
    for row in cursor.fetchall():
        title = {
            "title": row[fields["title"]],
            "from_date": row[fields["from_date"]],
            "to_date": row[fields["to_date"]]
        }
        titles.append(title)
    employee["titles"] = titles
    return json.dumps({
        "status": "success",
        "employee": employee
    })

def isFieldValid(t, v):
    if t == "employee":
        return v in ["birdth_date", "first_name", "last_name", "hire_date"]
    else:
        return false

@app.route("/employee/<id>", methods=['PATCH'])
def setEmployee(id):
    id = int(id)
    content = request.json
    print(content)
    setList = ""
    data = []
    for k, v in content.iteritems():
        if not isFieldValid("employee", k):
            continue
        if setList != "":
            setList = setList + ", "
        setList = setList + k + "=%s"
        data.append(v)
    data.append(id)
    print(setList)
    print(data)
    connection = mariadb.connect(user='admin', password='q5XpRomdSr', database='employees', client_flags=[ClientFlag.FOUND_ROWS])
    cursor = connection.cursor()
    cursor.execute("UPDATE employees SET {} WHERE emp_no = %s".format(setList), data)
    connection.commit()
    if cursor.rowcount < 1:
        abort(404)
    return json.dumps({
        "status": "success"
    })

@app.route("/salary", methods=['PUT'])
def putSalary():
    content = request.json
    print(content)
    connection = mariadb.connect(user='admin', password='q5XpRomdSr', database='employees', client_flags=[ClientFlag.FOUND_ROWS])
    cursor = connection.cursor()
    data = [content["emp_no"], content["salary"], content["from_date"], content["to_date"]]
    cursor.execute("INSERT INTO salaries (emp_no, salary, from_date, to_date) VALUES (%s, %s, %s, %s)", data)
    connection.commit()
    return json.dumps({
        "status": "success"
    })


@app.route("/state", methods=['GET'])
def getState():
    return json.dumps({
        "status": "success",
        "state": "working"
    })

if __name__ == '__main__':
    app.run(host='0.0.0.0',port='5002')

Tūpato Kaua rawa e waiho tenei ratonga hei tauira, hei kaiarahi ranei!

Ka mahia nga whakamatautau ma te whakamahi i te JMeter tawhito pai. He raupapa o nga whakamatautau mai i te 15 meneti ki te 2 haora i whakarewahia, kaore he aukati, he rereke te paheketanga o nga tono, he rereke te puta mai i te 300 ki te 600 tono mo ia meneti. Te maha o nga miro mai i te 50 ki te 500.

Na te mea he iti rawa te putunga korero, ko te whakahau:

mysql -e "SHOW ENGINE INNODB STATUS"

E whakaatu ana:

Buffer pool hit rate 923 / 1000, young-making rate 29 / 1000 not 32 / 1000

Kei raro nei nga wa whakautu toharite mo nga tono:

Tapanga

Toharite

Median

90%Raina

95%Raina

99%Raina

min

Max

whiwhi Kaimahi

37.64

12.57

62.28

128.5

497.57

5

4151.78

getState

17

7.57

30.14

58.71

193

3

2814.71

patchKaimahi

161.42

83.29

308

492.57

1845.14

5

6639.4

hoatuTe utu

167.21

86.93

315.34

501.07

1927.12

7

6722.44

He uaua pea ki a koe ki te whakatau mai i enei hua hangahanga he pehea te pai o tenei VPS mo o mahi motuhake, a, i te nuinga o te waa, ko nga tikanga kua whakarārangihia he iti noa ki nga keehi i mahia e matou i tetahi ahua, i tetahi atu. mārama e kore e pau. Ka tono matou ki a koe ki te tuhi i a koe ake whakatau me te whakamatautau i te tūmau mo te 30 rubles mo o tono me o mahi me te whakaatu i o whiringa mo tenei whirihoranga i roto i nga korero.

Source: will.com

Tāpiri i te kōrero