A, epoll
Tip beginning: epoll available only in linux Due to select only handle 1024 simultaneous clients, if there are more clients, it can not handle,
and therefore provides a linux epoll this multiplexed IO model, pay attention to other platforms without a corresponding
implementation. select and epoll difference: select realization: 1. First of all into a socket list = RLIST [SOCKET1, SOCKET2, ...] 2 . This list traversal process A added to the wait queue of each socket and then block the process 3 When the data arrives, cpu execute the interrupt program will copy the data to the socket at the same time awaken in a waiting
queue process a In order to prevent repeated the process to add the waiting queue also need to remove the existing A 4 . A wake-up process after that is not clear because the socket has data, it is necessary to traverse through all socket
list select disadvantages: 1 .Select socket need to traverse the list, the waiting queue for frequent removal operations add 2 after data arrives also you need to traverse all socket in order to learn which socket has data These two operations consume time increases with the number to be monitored socket is greatly increased, for
efficiency reasons only specifies the maximum can only monitor the 1024 socket
epoll implementation: epoll solve the problem: 1 . Avoid frequent operation of the waiting queue 2 . Avoided through all socket In epoll, the first problem to solve: import socket,select server = socket.socket() server.bind(("127.0.0.1",1688)) server.listen(5) # Create epoll event object, the follow-up to monitor the event to which the epoll = select.epoll () # registration server listens fd to wait for read event collection epoll.register (server.fileno (), select.EPOLLIN) # need to shut
Notes server the socket-readable event # Wait for events the while True: for our sock, Event in epoll.poll (): Pass In epoll in epoll.poll the blocking process register and unregister function is used for
maintaining a waiting queue register process is added to the waiting queue unregister the process is removed from the waiting queue Using these two functions to control our own wait queue to add and remove in order to avoid frequent operation waiting
queue
The second problem is in the process can not select which socket is to know which data needs to traverse so epol To solve this problem, maintain a ready list in the kernel 1 . Create Object epoll, epoll also corresponds to a file managed by the file system 2 when executed Register, added to the waiting queue epoll objects in the socket 3 after the data arrives, the CPU executes the interrupt program, copy the data to the socket . 4 in epoll, the interrupt program will be executed next epoll object callback function, passing-ready
socket object 5 . the socket, ready to add to the list 6 . wake epoll queue of waiting processes After the wake-up process, due to the ready list, so no need to traverse the socket, and is ready to deal directly with columns of
the table can be To solve these two problems, the amount of concurrency has been greatly improved, while maintaining the maximum level of thousands of socket
epoll Code: # Client Import socket client=socket.socket() client.connect( ('127.0.0.1',1688)) while True: data =input('input:') if data == "q": break if not data: continue client.send(data.encode("utf-8")) Data = client.recv (1024 ) Print ( ' data received by the client: ' , Data) client.close() # Server: import select,socket server=socket.socket() server.bind(('127.0.0.1',1688)) server.listen(5) epoll=select.epoll() epoll.register(server.fileno(),select.EPOLLIN) socket_fd={server.fileno():server} msgs=[] while True: for fd,event in epoll.poll(): sock=socket_fd[fd] if sock==server: client,addr=sock.accept() epoll.register(client.fileno(),select.EPOLLIN) socket_fd[client.fileno()]=client elif event==select.EPOLLIN: data=sock.recv(2048) if not data: epoll.unregister(sock.fileno()) del socket_fd[sock.fileno()] sock.close() continue # sock.send(data+b'sd') epoll.modify(sock.fileno(),select.EPOLLOUT) msgs.append((sock,data)) elif event==select.EPOLLOUT: for i in msgs[:]: if i[0]==sock: sock.send(i[1] + b'sd') msgs.remove(i) epoll.modify(sock.fileno(),select.EPOLLIN)
Second, the database concepts
TCP is essentially a database program structure CS, the client connects to the server transmits to the server instruction,
to accomplish the data
Data Data:
Symbol Symbol recording said things called data, describe things can be both digital, it can be text, pictures,
images, sounds, language, data from a variety of forms, they can be digitally stored after computer
Database DataBase, referred to DB:
Database data that is stored in the warehouse, the warehouse is only on a computer storage device, and the data is according to
a certain format storage
Long-term database is stored in the computer, organized, sharable data can be.
Data in the database according to certain organizational data model, described and storage, has a smaller redundancy, higher
data independence and easy scalability, can be shared for various users
DBMS DataBase Management System referred DBMS:
Scientific organization and storage of data, efficient data acquisition and maintenance of a system software
Such as MySQL, Oracle, etc.
Correspondence between the database and the file system:
Data: nature is part of a row in the data file
Record: document is essentially a row of data
Table: a file
Database: Folder
DBMS: Database Management System
Database server: computer running DBMS
Three, mysql
MySQL: a relational database management systems. # Software mysql is based on a written socket C / S architecture # client software mysql comes with: command such as mysql, mysqldump commands python modules: The pymysql Installation: 1 Download extract package 2 . Extract to a directory 3 . Add the environment variable The system will copy the bin to add the full path to where the path of 4 . It should be self-starting as a server mysql server Requires System Services mysqld - install the input services run to see whether success To delete a service sc delete mysql If you need to reinstall, then ... Start Service net start mysql Stop service net stop mysql
mysql connect to the server: TCP is the essence of the program, you must specify the ip and port, can be omitted if the server is running on this machine ip
if the port did not turn over the port can also be omitted MySQL -HIP -P port -u username - the p-password Examples: MySQL -uroot-- the p- MySQL 5.6 default is no password Modify the administrator password: 1 . If you know the original password can use this tool mysqladmin mysqladmin -p old password - U username password new password Example: mysqladmin -uroot--p password 123 2 . Without knowing the original password: skip the authorization form that we can start the server
specify allowed to ignore the authorization information 1 first administrator to stop the service net stop mysql. Performing mysqld --skip-grant- Tables 2 and then open another cmd, the following code is executed: No root account password MySQL -uroot-- the p- 3 . Execute update statement update mysql.user set password = password("123")
where user="root" and host = "localhost"; 4.刷新权限 flush privileges; The first open mysql service, and then restart the server command line to verify a new password