mardi 30 juin 2015

MySQL Crash: Cronjobs bringen MySQL DB nach einigen Stunden zum Absturz (Ram Problem)

Hallo an alle,

wir haben ein PHP script, dass mit verschiedenen GET Parametern als CRON Job 30 mal parallel läuft. Es geht hier um eine Art Suchmaschine mit Crawlingprozessen.

Nach jedem Crawl wird eine Zeile in ein csv file geschrieben und dieses wird bei 5000 oder 10000 Zeilen dann per load_data_infile in eine Tabelle gepumpt. (das Ganze aber 33.000 mal hintereinander)

Die Tabelle hat derzeit ca. 14 Mio EInträge und es werden bis zu 140 insgesamt noch werden.

Um die Geschwindigkeit des Ganzen etwas zu erhören macht das alles nicht ein script sondern 30 nebeneinander, die sozusagen 30 "kleinere Blöocke" abarbeiten....

Ich hab mir unter Linux / Debian mal mit top oder htop meine Prozesse angesehen und ich muss sagen am Anfang wars schon fast langweilig, weil schon wirklich alles zu gut lief (hatte anfangs Bedenken wegen der Performance) und jetzt nach 6 Stunden ca. ist der Server komplett überfordert und in die Knie gegangen (komplett Ausfall und down)

Das eigentliche Problem ist folgendes:

als die 30 Cronjobs liefen hat ein Cronjob 0,4% RamUsage gehabt, also jeder Prozess.

nun, nach 6 Stunden war es über das 10fache 5%RamUsage obwohl die Scripte nichsts anderes tun oder irgendwelche neuen Prozesse auslösen oder so...

ein script macht nichts anderes als eine Verbindung zu öffnen, crawling (dauert 1 Sek. ein Crawl) und dann diverese Ergebnisse wie meta Date oder Title oder so in die DB einzutragen und am Ende die Verbindung zu schließen (wozu es nie kommt, weil das script ja nie zu ende läuft, weil die DB ja absstürzt, wegen zu großen Prozessen)

Habe natürlich lange gegoogled, aber ich weiß nicth genau was ich jetzt optimieren sollte...


Mein System:

- 4 x 1,1 GHZ QuadCore
- 1 GB Ram
- Debian
- nginx Webserver

und die Dateien wurde aber alle über crontab unter linux zeitgesteuert aufgerufen...


Angehängt hab ich die Tabellen / DB Struktur, die Caching Variablen von Mysql UND mein Auszug aus dem Tuning-Primer und auch noch den htop Auslastungs Auszug:
den hab ich mir angeschaut und so auch festgehalten und das war schon kritisch find ich und dann 6 Stunden später war der MysqlDeamon tot







Code:

        -- MYSQL PERFORMANCE TUNING PRIMER --
            - By: Matthew Montgomery -

MySQL Version 5.5.43-0+deb7u1 armv7l

Uptime = 0 days 8 hrs 2 min 48 sec
Avg. qps = 0
Total Questions = 1275
Threads Connected = 1

mWarning: mServer has not been running for at least 48hrs.
mIt may not be safe to use these recommendations

To find out more information on how each of these
runtime variables effects performance visit:
http://ift.tt/1hORI36
Visit http://ift.tt/N74Fri
for info about MySQL's Enterprise Monitoring and Advisory Service

SLOW QUERIES
The slow query log is mNOT enabled.
Current long_query_time = 10.000000 sec.
You have m2 out of m1296 that take longer than 10.000000 sec. to complete
Your long_query_time seems to be fine

BINARY UPDATE LOG
The binary update log is mNOT enabled.
You will not be able to do point in time recovery
[33mSee http://ift.tt/1hORI3d

WORKER THREADS
Current thread_cache_size = 8
Current threads_cached = 5
Current threads_per_sec = 0
Historic threads_per_sec = 0
Your thread_cache_size is fine

MAX CONNECTIONS
Current max_connections = 151
Current threads_connected = 1
Historic max_used_connections = 6
The number of used connections is 3% of the configured maximum.
You are using less than 10% of your configured max_connections.
Lowering max_connections could help to avoid an over-allocation of memory
See "MEMORY USAGE" section to make sure you are not over-allocating

INNODB STATUS
Current InnoDB index space = 0 bytes
Current InnoDB data space = 0 bytes
Current InnoDB buffer pool free = 97 %
Current innodb_buffer_pool_size = 128 M
Depending on how much space your innodb indexes take up it may be safe
to increase this value to up to 2 / 3 of total system memory

MEMORY USAGE
Max Memory Ever Allocated : 192 M
Configured Max Per-thread Buffers : 405 M
Configured Max Global Buffers : 176 M
Configured Max Memory Limit : 581 M
Physical Memory : 927 M
Max memory limit seem to be within acceptable norms

KEY BUFFER
Current MyISAM index space = 202 M
Current key_buffer_size = 16 M
Key cache miss rate is 1 : 1
Key buffer free ratio = 87 %
Your key_buffer_size seems to be fine

QUERY CACHE
Query cache is enabled
Current query_cache_size = 16 M
Current query_cache_used = 41 K
Current query_cache_limit = 1 M
Current Query cache Memory fill ratio = .25 %
Current query_cache_min_res_unit = 4 K
Your query_cache_size seems to be too high.
Perhaps you can use these resources elsewhere
[33mMySQL won't cache query results that are larger than query_cache_limit in size

SORT OPERATIONS
Current sort_buffer_size = 2 M
Current read_rnd_buffer_size = 256 K
No sort operations have been performed
Sort buffer seems to be fine

JOINS
Current join_buffer_size = 132.00 K
You have had 0 queries where a join could not use an index properly
Your joins seem to be using indexes properly

OPEN FILES LIMIT
Current open_files_limit = 1024 files
[33mThe open_files_limit should typically be set to at least 2x-3x
[33mthat of table_cache if you have heavy MyISAM usage.
Your open_files_limit value seems to be fine

TABLE CACHE
Current table_open_cache = 400 tables
Current table_definition_cache = 400 tables
You have a total of 55 tables
You have 55 open tables.
The table_cache value seems to be fine

TEMP TABLES
Current max_heap_table_size = 16 M
Current tmp_table_size = 16 M
Of 928 temp tables, 19% were created on disk
Created disk tmp tables ratio seems fine

TABLE SCANS
Current read_buffer_size = 128 K
Current table scan ratio = 178 : 1
read_buffer_size seems to be fine

TABLE LOCKING
Current Lock Wait ratio = 0 : 1554
Your table locking seems to be fine


Miniaturansicht angehängter Grafiken
Klicke auf die Grafik für eine größere Ansicht Name: 3.png Hits: - Größe: 99,8 KB ID: 5531   Klicke auf die Grafik für eine größere Ansicht Name: 2.png Hits: - Größe: 36,6 KB ID: 5532   Klicke auf die Grafik für eine größere Ansicht Name: 4.jpg Hits: - Größe: 452,7 KB ID: 5533  


Aucun commentaire:

Enregistrer un commentaire