Boko + VPS bakeng sa li-ruble tse 30 =?

Ho monate haholo ha lintho tsohle tse nyane tse hlokahalang li le teng: pene e ntle le notepad, pentšele e bohale, toeba e phutholohileng, lithapo tse 'maloa tse eketsehileng, joalo-joalo. Lintho tsena tse sa bonahaleng ha li hohele tlhokomelo, empa li eketsa matšeliso bophelong. Pale e ts'oanang e na le lits'ebetso tse fapaneng tsa mehala le li-desktop: bakeng sa li-screenshots tse telele, bakeng sa ho fokotsa boholo ba setšoantšo, bakeng sa ho bala lichelete tsa motho, dikishinari, bafetoleli, bafetoleli, joalo-joalo. O na le eona? VPS - e leng e theko e tlaase, e lulang e le teng 'me e tlisa melemo e mengata? Che, eseng eo u nang le eona k'hamphaning ea hau, empa ea hau, "pokothong" ea hau. Re ne re nahana hore ntle le VPS e nyane ka 2019 ho ne ho hloname ka tsela e itseng, joalo ka ntle le pene e tloaelehileng ea seliba puong. Ke hobane'ng ha u hloname? Ke lehlabula. Ho joang lehlabula? Lehlabula bakeng sa setsebi sa IT: ho lula lapeng, ho sebetsa mererong eo ue ratang haholo ntle le ho ikoahlaea. Ka kakaretso, re ile ra nahana le ho e etsa.

Boko + VPS bakeng sa li-ruble tse 30 =?
Bokomonisi bo fihlile, baheso.

O joalo - VPS ea rona ka mashome a mararo

Re balile lihlooho tse ngata tse tsoang ho bahlolisani le basebelisi ba ngotseng lilemo tse 3-4 tse fetileng mabapi le hore na ke hobane'ng ha VPS e theko e tlaase e sa hlokahale. Ho joalo, ho joalo, joale VPS "bakeng sa penny" e ne e le papatso e hloekileng 'me e sitoa ho fana ka menyetla e tloaelehileng ea ho sebetsa. Empa linako lia fetoha, litšenyehelo tsa lisebelisoa tse fumanehang li ntse li fokotseha, 'me bakeng sa li-ruble tse 30 ka khoeli re itokiselitse ho fana ka sena:

  • Motlakase: Intel Xeon 2 GHz (1 konokono)
  • Sistimi ea Linux (Debian, Ubuntu, CentOS eo u ka khethang ho eona)
  • 1 aterese e khethehileng ea IPv4
  • 10 GB ea polokelo ea data ho li-drive tsa SSD tsa maemo a potlakileng
  • RAM: 512 MB
  • Tefiso ea motsotsoana
  • Sephethephethe se se nang moeli

Therifi e itšetlehile ka lithibelo tse eketsehileng tsa tekheniki, lintlha tse mabapi le leqephe tlhahiso ea rona e pholileng - VPS bakeng sa li-ruble tse 30. 

Seva ee ea sebele e loketse mang? E, hoo e batlang e le motho e mong le e mong: ba qalang, ba chesehang, bahlahisi ba nang le phihlelo, libapali tsa DIY esita le lik'hamphani tse ling.

VPS ee e loketse eng?

Re nahana hore babali ba Habr ba tla fumana mokhoa oa bona oa ho sebelisa tlhophiso ena, empa re nkile qeto ea ho bokella mehopolo ea rona - ho thoe'ng haeba motho a e hloka, empa banna ha ba tsebe?

  • Beha sebaka sa hau sa marang-rang se bonolo, potefolio, qala hape ka khoutu, joalo-joalo. Ehlile, sebaka sa hau sa marang-rang se entsoeng se etsa maikutlo a matle ho mohiri. E behe ho VPS ea hau 'me u be le boikarabelo ba ts'ireletso le botsitso ba sebaka sa hau, eseng ka basebetsi ba bafani ba kamehla ba amohelang baeti.
  • Sebelisa VPS molemong oa thuto: amohela projeke ea hau, ithute likarolo tsa sistimi ea ts'ebetso ea seva le seva, leka DNS, tinker ka sebaka se senyenyane sa thuto.
  • Bakeng sa mohala. Ka linako tse ling rakhoebo ka bomong, motho ea ikemetseng kapa k'hamphani e nyane haholo o hloka mohala oa IP haholo, mme basebelisi ba mohala ona ba meharo haholo. Ho bonolo: re nka seva sa rona, re reka nomoro ho IP telephony operator, re theha PBX ea sebele le ho etsa linomoro tsa ka hare (haeba ho hlokahala). Lipolokelo li ngata haholo.
  • Sebelisa seva ho lekola lits'ebetso tsa hau.
  • Sebelisa seva bakeng sa liteko tsa DIY, ho kenyelletsa ho laola le ho bokella lintlha ho tsoa ho lisensara tse bohlale tsa lapeng.
  • Tsela e sa tloaelehang ea ho e sebelisa ke ho beha mothusi oa khoebo ea phapanyetsano ea sebele, roboto ea khoebo, ho seva. U tla ikarabella ka botlalo bakeng sa botsitso le ts'ireletso ea seva, ho bolelang hore u tla fumana sesebelisoa se laoloang bakeng sa ho rekisa limmarakeng tsa lichelete. Leha ho le joalo, haeba mang kapa mang a thahasella kapa a rera :)

Ho na le likopo tsa VPS e joalo lefapheng la khoebo. Ho phaella tšebeletsong ea thelefono e seng e boletsoe, u ka kenya ts'ebetsong lintho tse 'maloa tse thahasellisang. Ka mohlala:

  • Beha li-database tse nyane le tlhaiso-leseling e tla fumaneha ho basebetsi ba tsamaeang ba le hole, mohlala, ho sebelisa ftp. Sena se tla u lumella ho fapanyetsana li-analytics tse ncha kapele, litlhophiso tse ntlafalitsoeng bakeng sa barekisi, lipuo, joalo-joalo.
  • Fana ka phihlello ea nakoana ho basebelisi kapa bareki ho bonts'a software kapa media.

VPS test drive bakeng sa li-ruble tse 30 - e etselitsoe uena

Li-ruble tse 30 li nyenyane hoo u sa batleng ho ntša karete ho lefa le ho hlahloba. Le rona ka linako tse ling rea botsoa, ​​​​empa lekhetlong lena re u etselitse tsohle. Pele re qala li-server ntoeng, re ile ra etsa liteko ho lekola lintlha tsohle le ho bonts'a hore na li-server li khona ho etsa eng ka litefiso tsena. Ho etsa hore e thahasellise le ho feta, re ekelitse ho feteletseng mme ra hlahloba hore na tlhophiso ena e tla sebetsa joang haeba letsoalo le mojaro li feta boleng boo re bo behileng. 

Moamoheli o ne a le tlas'a mojaro oa mechini e mengata e sebetsang e neng e etsa mesebetsi e fapaneng ho processor mme e sebelisa sistimi e nyane ea disk ka mafolofolo. Sepheo ke ho etsisa palo e phahameng ea sebaka le mojaro o ka bapisoang le kapa o moholo ho feta oa ntoa.

Ntle le mojaro o sa khaotseng, re kentse mechini e 3 e bokelletsoeng e neng e bokella metrics ea maiketsetso e sebelisang sysbench, liphetho tse tloaelehileng tse fanoeng ka tlase, le mechini e 50 e entseng moroalo o eketsehileng. Mechini eohle ea tlhahlobo ea liteko e ne e e-na le tlhophiso e tšoanang (1 konokono, RAM 512 GB, SSD 10 GB), setšoantšo se tloaelehileng sa debian 9.6 se khethiloe e le sistimi e sebetsang, e fuoang basebelisi ho RUVDS.

Mojaro o ile oa etsisoa ka tlhaho le boholo bo bapisoang le ntoa:

  • Mechini e meng ea sebele e ile ea qalisoa ka mojaro o tlase
  • Mechini e meng e ne e tsamaisa mongolo oa liteko o etsisang mojaro ho processor (e sebelisa sesebelisoa khatello ea kelello)
  • Karolong e setseng ea mechini ea sebele, re ile ra tsamaisa script e sebelisang dd ho kopitsa data ho tloha ho data e lokiselitsoeng pele ho disk ka moeli o behiloeng ho sebelisa pv (mehlala e ka bonoa. mona и mona).

Hape, joalo ka ha u hopola, re ne re e-na le mechini e meraro e neng e bokella metrics ea maiketsetso.

Mochineng o mong le o mong, mongolo o ne o etsoa ka lebelo metsotso e meng le e meng e 15, e tsamaisang liteko tse tloaelehileng tsa sysbench bakeng sa processor, memori le disk.

Script sysbench.sh

#!/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

Liphetho li hlahisoa molemong oa sebopeho sa sysbench, empa litekanyetso tse tloaelehileng tsa nako eohle ea liteko li nkiloe mochining oohle, sephetho se ka bonoa mona:

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

Liphetho ke sesupo, empa leha ho le joalo ha lia lokela ho nkuoa joalo ka QoS. 

Mechini e etsang mojaro o eketsehileng

Software:

  • E fumaneha ka mokhoa o nepahetseng
  • ntlafatso e loketseng
  • apt-get kenya python-pip
  • pip kenya mysql-connector-python-rf

E kentse MariaDB, Mokhoa oa ho mona:

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

Setsi sa liteko se nkuoe ho tloha mona:

Database e tsamaisoa ka tsela e boletsoeng mona:

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

Motheo oa tlhahlobo e nyane:

Lethathamo 

RowsCount 

Boholo ba data (MB)

Boholo ba index (KB)

litšebeletso 

9

0.02

16.00

dept_emp 

331143 

11.52

5648.00

dept_manager 

24 

0.02

16.00

basebetsi ba 

299379 

14.52

0.00

meputso 

2838426 

95.63

0.00 

litlotla 

442783 

19.56

0.00

Ts'ebeletso ea tlhahlobo ea khale e ngotsoe ka lengole ho Python; e etsa lits'ebetso tse 'ne:

  1. getState: e khutlisetsa boemo
  2. getEmployee: khutlisa basebetsi (+meputso, +litlotla) ho tsoa ho database
  3. patchEmployee: fetola masimo a basebetsi
  4. insertSalary: kenya moputso

Mohloli oa litšebeletso (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')

Ela hloko ka kopo! Tlas'a maemo a itseng tšebeletso ena ha ea lokela ho nkoa e le mohlala kapa tataiso!

Liteko li etsoa ho sebelisoa JMeter ea khale ea khale. Letoto la liteko tse nkang metsotso e 15 ho isa ho lihora tse 2 li ile tsa qalisoa, ntle le litšitiso, liperesente tsa likopo li ile tsa fapana, 'me liphetho li fapana ho tloha ho 300 ho isa ho 600 likopo ka motsotso. Palo ea likhoele ho tloha ho 50 ho isa ho 500.

Ka lebaka la hore database e nyane haholo, taelo ena:

mysql -e "SHOW ENGINE INNODB STATUS"

E bontša hore:

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

Ka tlase ke kakaretso ea linako tsa karabo ea likopo:

Label

karolelano

E bohareng

90%Mola

95%Mola

99%Mola

mets

Max

fumana Mosebetsi

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

patchMosebetsi

161.42

83.29

308

492.57

1845.14

5

6639.4

putSalary

167.21

86.93

315.34

501.07

1927.12

7

6722.44

Ho ka 'na ha e-ba thata ho uena ho ahlola ho latela liphello tsena tsa maiketsetso hore na VPS ena e loketse hakae bakeng sa mesebetsi ea hau e khethehileng,' me, ka kakaretso, mekhoa e thathamisitsoeng e lekanyelitsoe ho linyeoe tseo re neng re tlameha ho sebetsana le tsona ka mokhoa o mong. ka ho hlaka ha e felle. Re u mema hore u iketsetse liqeto 'me u leke seva bakeng sa li-ruble tse 30 lits'ebetsong tsa hau tsa' nete le mesebetsi, 'me u fane ka maikutlo a likhetho tsa hau bakeng sa tlhophiso ena ho maikutlo.

Source: www.habr.com

Eketsa ka tlhaloso