python astモジュール

The ast module makes it easy to handle Python abstract syntax trees in Python applications. The abstract syntax itself can change with every release of Python. Using this module will help to learn the current grammer programmatically.

To create an abstract syntax tree, pass ast. PyCF_ONLY_AST as a flag for the built-in function compile() or use the helper function parse() provided by this module. The result is a tree of objects of classes that inherit from ast.AST. Abstract syntax trees can be compiled into Python code objects using the built-in function compile().

[vagrant@localhost test]$ python --version
Python 3.5.2
[vagrant@localhost test]$ cat << 'EOF' > helloworld.py
> !#/usr/bin/env python
> # -*- coding: utf-8 -*-
>
> def main():
>   print('hello, world!')
>
> if __name__ == '__main__':
>   main()
> EOF

[vagrant@localhost test]$ python
Python 3.5.2 (default, Jul 28 2018, 11:25:01)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux
Type “help”, “copyright”, “credits” or “license” for more information.
>>> FILENAME = ‘helloworld.py’
>>> with open(FILENAME, ‘r’) as f:
… source = f.read()
File ““, line 2
source = f.read()
^
IndentationError: expected an indented block

あれ、うまくいかんな。。

ib_logfile*

ibdata* is a shared table space (It managed all data)
ib_logfile* seems to be a log file.

Data is not updated directory to the table space, but once the update contents are written to the log file.
After that, it seems that the flow is reflected in table space.
Tablespace updates are expensive and are not reflected immediately.
By writing to the log file, the writing performance is improved.

中身を見てみましょう

cd /var/lib/mysql
ls
sud cat ib_logfile0

なんじゃこりゃーー

InnoDB

– Default storage engine from MySQL5.5
– General purpose storage engine with good balance of reliability and performance.
– DML operations process transactions according to the ACID model, such as commit rollback and crash recovery
– Data is aligned on disk so that queries are optimized based on primary key
– Operations that call different storage engine tables can be mixed in one query
– Foreign key constraints are also supported
– InnoDB stores in tablespaces whereas MyISAM always stores data in file
– The good thing about MyISAM is that it can be easily backed up and copied in units of tables, but innoDB is still poorly managed in this respect.
– Table spaces can be stored in files, but can also be written directly to partitions.
– There is unique buffer pool for caching data and indexes in many mamory, which helps high speed data access.

う~ん、。。。

ibdata1には何が入っているのか?

$ sudo cat /var/lib/mysql/ibdata1
ん?

# ./innochecksum /var/lib/mysql/ibdata1
0 bad checksum
13 FIL_PAGE_INDEX
19272 FIL_PAGE_UNDO_LOG
230 FIL_PAGE_INODE
1 FIL_PAGE_IBUF_FREE_LIST
892 FIL_PAGE_TYPE_ALLOCATED
2 FIL_PAGE_IBUF_BITMAP
195 FIL_PAGE_TYPE_SYS
1 FIL_PAGE_TYPE_TRX_SYS
1 FIL_PAGE_TYPE_FSP_HDR
1 FIL_PAGE_TYPE_XDES
0 FIL_PAGE_TYPE_BLOB
0 FIL_PAGE_TYPE_ZBLOB
0 other
3 max index_id

checksum以外は、FIL_PAGE_*だな。FILって何の略だろうか?

ibdata1には何が入っているのか?
– データディクショナリ(InnoDBテーブル)
– チェンジバッファ
– ダブルライトバッファ
– UNDOログ

んん??

disabled属性

buttonにdisabledを追加します。

<button disabled>ボタン</button><br>
<button>ボタン2</button>

なるほど、こうやって表示されるのかー

通信タイムアウト

通信タイムアウトの状況

デフォルトの制限値は30secondとあり、デフォルト値のままですね。
では、公式に沿って試してみましょう。

set_time_limit(20);

while ($i <= 10){ echo "i=$i "; sleep(100); $i++; } [/php] ん、止まってしまった。 sleep(100)の10回はさすがにやりすぎか。

What is load average?

Load average is an indicator that represents the load status of the entire system. It is represented by “the number of processes waiting for “the number of processes waiting for execution per unit time and disk I/O waiting for one CPU”.

If yuo want to increase the throughput of the system, the goal is to reduce the load average.

The Linux kernel has a process descriptor for each process, and manages the state of the process in its state member. The state of the process is distinguished as follows.

TASK_RUNNING: Possible state. It can be run if the CPU is free.
TASK_UNINTERRUPTABLE: Uninterruptible wait state. Those that return in a short time, such as waiting for disk I/O.
TASK_INTERRUPTABLE: An interruptible wait state. The return time can not be predicted, such as waiting for user input.
TASK_STOPPED: Execution has been suspended. It will not be scheduled until it is resumed.
TASK_ZOMBIE: Zombie process. The child process has not exited and has not been waited on by the parent process.

ロードアベレージを確認するコマンド
[vagrant@localhost ~]$ uptime
08:42:40 up 1 day, 16:57, 1 user, load average: 0.00, 0.00, 0.00
[vagrant@localhost ~]$ uptime
08:43:36 up 1 day, 16:58, 2 users, load average: 0.13, 0.03, 0.01

[vagrant@localhost ~]$ w
08:44:33 up 1 day, 16:59, 2 users, load average: 0.05, 0.02, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
vagrant pts/1 192.168.35.1 08:43 1:08 0.42s 0.24s php -S 192.168.
vagrant pts/0 192.168.35.1 23:24 1.00s 7.38s 0.01s w

[vagrant@localhost ~]$ top
top – 08:45:38 up 1 day, 17:00, 2 users, load average: 0.02, 0.02, 0.00
Mem: 501796k total, 493992k used, 7804k free, 6144k buffers
Swap: 1015804k total, 419948k used, 595856k free, 30000k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
6854 vagrant 20 0 100m 700 468 S 51.0 0.1 0:00.34 sshd
9368 vagrant 20 0 15020 1308 1008 R 51.0 0.3 0:00.28 top
1 root 20 0 19232 192 60 S 0.0 0.0 0:00.90 init
2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd
3 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/0
4 root 20 0 0 0 0 S 0.0 0.0 0:01.62 ksoftirqd/0
5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 stopper/0
6 root RT 0 0 0 0 S 0.0 0.0 0:00.63 watchdog/0
7 root 20 0 0 0 0 S 0.0 0.0 3:13.04 events/0
8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 events/0
9 root 20 0 0 0 0 S 0.0 0.0 0:00.00 events_long/0
10 root 20 0 0 0 0 S 0.0 0.0 0:00.00 events_power_ef
11 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cgroup
12 root 20 0 0 0 0 S 0.0 0.0 0:00.00 khelper
13 root 20 0 0 0 0 S 0.0 0.0 0:00.00 netns
14 root 20 0 0 0 0 S 0.0 0.0 0:00.00 async/mgr
15 root 20 0 0 0 0 S 0.0 0.0 0:00.00 pm
16 root 20 0 0 0 0 S 0.0 0.0 0:01.11 sync_supers
17 root 20 0 0 0 0 S 0.0 0.0 0:00.02 bdi-default

おおおおおおおおおお、なんかわかった気になってきた。すげえ。

Take a look at the MySQL binary log

The binary log has not been output yet.
[vagrant@localhost ~]$ ls /var/lib/mysql/
addb count equity ibdata1 mysql.sock zeus
auto.cnf demo ib_logfile0 laravel57 performance_schema
click dev ib_logfile1 mysql test

Add log-bin and configure to output binary log.
log-binを足します。
[vagrant@localhost ~]$ sudo vi /etc/my.cnf
[vagrant@localhost ~]$ cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

character_set_server=utf8
default-storage-engine=InnoDB
innodb_file_per_table

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# Settings user and group are ignored when systemd is used (fedora >= 15).
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mysqld according to the
# instructions in http://fedoraproject.org/wiki/Systemd
user=mysql

# Semisynchronous Replication
# http://dev.mysql.com/doc/refman/5.5/en/replication-semisync.html
# uncomment next line on MASTER
;plugin-load=rpl_semi_sync_master=semisync_master.so
# uncomment next line on SLAVE
;plugin-load=rpl_semi_sync_slave=semisync_slave.so

# Others options for Semisynchronous Replication
;rpl_semi_sync_master_enabled=1
;rpl_semi_sync_master_timeout=10
;rpl_semi_sync_slave_enabled=1

# http://dev.mysql.com/doc/refman/5.5/en/performance-schema.html
;performance_schema

[mysql]
default-character-set=utf8

[mysqldump]
default-character-set=utf8

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
log-bin

[vagrant@localhost ~]$ sudo service mysqld restart
mysqld を停止中: [ OK ]
mysqld を起動中: [ OK ]
[vagrant@localhost ~]$ ls /var/lib/mysql/
addb count equity ibdata1 mysql.sock zeus
auto.cnf demo ib_logfile0 laravel57 performance_schema
click dev ib_logfile1 mysql test

あれ、、、、、、、、、、、、 bin-log出てないやんけ。おかしいな。。

mysql> create database sample;
Query OK, 1 row affected (0.02 sec)

mysql> quit
Bye
[vagrant@localhost ~]$ ls /var/lib/mysql/

log-binの追加する位置が悪いか。。

eval – catch exceptions, execute string dynamically

You can use the eval function to catch exceptions in the case of block syntax. For string syntax, you can execute strings dynamically.

eval 

eval $string;

The one called eval string is the syntax to execute the string dynamically. Passing a string to eval will execute that string as a Perl executable statement. Errors that occur at runtime are stored in $@.

As an example, you can define a subroutine at runtime. The following example defines an eval string and a typeglob at runtime for a subroutine that return 5 foo: Temporarily allow symbolic references with no string refs.

#!/usr/bin/perl --

{
	no strict = 'refs';
	*{"foo"} = eval "sub {return 5}";
}
print "Content-type:text/html\n\n";
print $foo;

Internal Server Error

あれ?? 全然違う??