Building a server to manage high concurrent connections is non-trival task. For those developers that use ActionScript 3 to build games on the client side it means having a totally different skillset. Being able to use ActionScript 3 on the server to build MMO’s or port client code to the server allows developers to leverage their skills on the server.
By walking through a live game example with more then 15,000 concurrent connections running on a medium Amazon EC2 server the presentation will:
1. Introduce Linux server configuration for high concurrent connected usage.
2. Introduce Socket class based on libev library for high concurrent connection.
3. Introduce leveraging Tamarin project for ActionScript 3 on the server.
Building a server to manage high concurrent connections is non-trival task. For those developers that use ActionScript 3 to build games on the client side it means having a totally different skillset. Being able to use ActionScript 3 on the server to build MMO’s or port client code to the server allows developers to leverage their skills on the server.
By walking through a live game example with more then 15,000 concurrent connections running on a medium Amazon EC2 server the presentation will:
1. Introduce Linux server configuration for high concurrent connected usage.
2. Introduce Socket class based on libev library for high concurrent connection.
3. Introduce leveraging Tamarin project for ActionScript 3 on the server.
3. A server process and one or more client
processes.
Server manages some resources.
Server provides services by manipulating
resource for clients.
5. Two common paradigms for clients and servers
communication
? Datagrams (UDP protocol, SOCK_DGRAM)
? Connections (TCP protocol, SOCK_STREAM)
Connections are point-to-point, full-duplex (2-
way communication), and reliable (only for TCP).
7. CLIENT SERVER
Client programs
? Web browsers, ftp, telnet,
ssh
How does a client find the
server?
? IP address
? Port
Servers are long-running
processes
Each server waits for
requests to arrive on a well-
known port associated with
a particular service.
9. Concurrency is a property of systems in
which several computations are executing
simultaneously, and potentially interacting
with each other.
? Single host, multiple processes
? Single process, multiple threads
12. UNIX domain socket
? Local IPC
? AF_LOCAL or AF_UNIX
? Filesystem: path name
Internet domain socket
? Internet communications
? IPv4: AF_INET
? IPv6: AF_INET6
? Internet address: IP + Port
15. Internet-specific socket address (IPv4):
<netinet/in.h> (Posix.1g)
? Must cast (sockaddr_in *) to (sockaddr *) for
connect(), bind(), and accept().
16. Generic socket address: <sys/socket.h>
? For address arguments to connect(), bind(), and
accept().
26. #include <sys/socket.h>
int socket (int family, int type, int protocol);
? returns: nonnegative integer descriptor if OK, -1 on
error
socket:用來建立一個 socket,回傳一整數的
descriptor (sockfd) family: protocol family
type: communication type
? protocol: 指定此 socket 所使用的傳輸通訊協定。
Specifying a protocol of 0 causes socket() to use an
unspecified default protocol appropriate for the
requested socket type (e.g., TCP/IP).
29. #include <sys/socket.h>
int bind (int sockfd, const struct sockaddr *myaddr,
socklen_t addrlen);
? returns: 0 if OK, -1 on error
bind:當 socket 建置時,並未宣告本機地址和遠
端主機的位址。伺服程式需用 bind 程序來將
socket與本機上的一個 port 相關聯,之後 server
就可以在該port 監聽服務請求。
? sockfd: 參數值為已建置但未指定 port number 的 descriptor
? *myaddr: 為在名本機位址的資料結構之起始位置
? addrlen: 為本機位址的資料結構之長度
30. #include <sys/socket.h>
int listen (int sockfd, int backlog);
? returns: 0 if OK,-1 on error
listen:當伺服程式宣告其通訊協定 port
number 後 (ex: bind),可要求 OS 將此 socket
設為被動的等待 client 來聯繫的模式。
? sockfd: 參數值為已建置且已指定 port number 的
descriptor
? backlog: 指定此 socket 的服務請求佇列 (request
queue) 的最大值
32. #include <unistd.h>
pid_t fork (void);
? returns: 0 in child, process ID of child in parent, -1 on
error (called-once-return-twice)
A child has only one parent process. It can use
getppid() to get parent’s PID.
If a parent want to get a child’s PID, it has to
record the return value of fork().
45. Signals
? “software interrupts”
? usually occur asynchronously.
? can be sent
by one process to another process (or to itself)
by the kernel to a process.
zombie
wait() && waitpid()
47. to be notified, by kernel, if one or more I/O
conditions are ready.
Scenarios in networking applications:
? a client handling multiple descriptors (stdio/socket)
? a client handling multiple sockets
? a TCP server handling a listening socket and its
connected sockets
? a server handling both TCP and UDP
? a server handling multiple services and protocols
48. wait for data; copy data from kernel to user
blocking I/O: blocked all the way
nonblocking I/O: if no data, immediate
returns EWOULDBLOCK
I/O multiplexing (select and poll): blocked
separately in wait and copy
signal driven I/O (SIGIO): nonblocked in wait
but blocked in copy (signaled when I/O can
be initiated)
asynchronous I/O (aio_): nonblocked all the
way (signaled when I/O is complete)
50. Synchronous I/O
? The requesting process to be blocked until that I/O
operation completes.
? blocking, non-blocking, I/O multiplexing, and
signal-driven I/O
Asynchronous I/O
? Does not cause the requesting process to be
blocked.
? Asynchronous I/O