Report from Moscow Django MeetUp No. 25
On February 10, the 25th Moscow Django Meetup was held at the IIDF Media Center (Internet Initiatives Development Fund) on Serebryanicheskaya Embankment. This is a monthly meeting of Django developers. Each meeting, several people make presentations to the public with reports related in one way or another to web development, Python and Django.
Briefly about the fund itself. IIDF helps online startups in the early stages of development. The fund has already launched its first startup accelerator in Moscow and is going to conduct several sets a year in the future. IIDF will also open accelerators in other cities in the near future. The IIDF's priorities are support for educational and infrastructure projects that promote the development in Russia of a full-fledged market for small and medium-sized Internet businesses.
“Either Docker or alcohol”
There were two reports on the agenda, the first of which was dedicated to Docker, the most actively developing open-source project in the last year. According to speaker Alexander Chistyakov, chief engineer of the consulting company Git In Sky, a new way of virtualization at the OS level makes life much easier during the development of web applications. With it, Git In Sky strives to increase its effectiveness in managing customer infrastructure.
Prior to Docker, there were several generations of technologies and virtualization servers. The most famous of them are XEN, KVM, LinuxV-server, OpenVZ, LXC.
Docker used to use LXC, but then they came up with their own tool - libcontainer. Now Docker can use other backends - Libvirt, LXC, systemd-nspawn and others. Docker containers work according to a rather old dependency injection scheme, i.e. the container does not know anything about the environment (the idea is purely programmatic, the system administrator would not do that).
The platform is designed to run applications in separate containers, which significantly changed the configuration of servers, their support and the principle of application deployment. Docker can help develop and deploy web applications and services. Containers are used to divide the application architecture into smaller parts (micro-services). The software at the same time remains isolated from the base system. This allows you to achieve greater acceleration and parallelism of execution. It is important that docker images are described through a declarative dockerfile and inherited from a single ancestor. Containers are self-contained and can be transferred without changes from one server to another or, for example, to the cloud. Developers can sleep peacefully by containerizing the application once, you don’t have to worry that the application will not start on another machine. Containers are designed to run on any server in the latest working, tested configuration. So, now sysadmins will have much less headaches due to software support.
Docker is supported by Linux distributions with the kernel version 3.8 and higher on many different platforms. In other words, this means that you can deploy a containerized application on any Linux machine from a laptop to the Amazon Elastic Compute Cloud. According to speaker Alexander Chistyakov, chief engineer of the consulting company Git In Sky, a new way of virtualization at the OS level makes life much easier during the development of web applications. As the speaker himself said, Docker is both a mushroom and a radio wave. With this reference, he led Docker to solve a number of problems:
- Automation of packaging and deployment of applications;
- Scaling of web services, databases and backend component;
- Possibility of continuous integration and deployment on a combat server;
- It provides services in the background, for example, PostgreSQL;
- Publish user images to a private repository or to hub.docker.com (A lot of complaints about the hub working unstable);
- Creating images of virtual machines (containers).
Docker is used as a means of hiding network abstraction (the operation of containers with the network is abstracted; you may not even know which ip your container has).
Keep in mind that if you restart Docker, all containers will fall.
Project Atomic from Red Hat engineers integrates tools and structures of the container application with deployment services, which makes it possible to more effectively manage the process of deploying containers. Project Atomic also allows you to do atomic system upgrades (rpm-ostree). Available for Fedora, CentOS, and Red Hat Enterprise.
Consul's Occupation System by Mitchell Hashimoto, author of Vagrant, written in Go, is generally a tool for configuring services in the infrastructure. It supports working with several data centers out of the box. Using Consul, applications can use hierarchical key-value storage.
Using Consul, you can automate the distribution of containers by hosts and the order in which they are started, register services and find them, and use them as a DNS emulation tool for containers.
Alexey Kinev continued the meeting with his report on the high-performance web server Tornado.
Tornado is a non-blocking, highly scalable web server that provides the developer with a set of tools. The framework applications are a regular web.py file (aka Google web application), but they have access to a number of additional tools that increase work efficiency and reveal the potential of the platform’s long session infrastructure.
Alexey shared his vision of the Tornado framework that he has been working with since 2012. The speaker suggested comparing Tornado and Django, which, to be honest, is not entirely correct. Although both frameworks are used in web development, they still have different architectures and have historically evolved in different directions, as the speaker himself noted. Unlike Django - full stack, Tornado is not very flexible and universal, but it is made with sharpening for speed. The speed is achieved thanks to the principle of using lengthy request processing (each active user uses an open connection to the server), which makes solid acceleration possible. This allows it to operate with thousands of one-time connections, which means that the framework is well suited for creating real-time web services.
Like Django, Tornado can work with web sockets, supports the MVC pattern. Particular attention was paid to warnings about a lower-level approach to developing and having a strictly defined entry point to the application (in Tornado, the application begins with the Handler construct), unlike Django, where there is no such point.
Tornado mainly works with the ioloop module. This module serves the entire application, tracking changes in the cycle, providing the ability to process the request for a long time. Call backs also come out of this cycle (they come at the level of events in the OS because they do not create separate threads, which allows you to win in speed).
In summary: Tornado is not a replacement for Django. This framework is more suitable for smaller tasks, between which you need to quickly switch.
Often the following moles are used in development: httpserver - HTTP server, (add-on on the web module), httpclient - HTTP client (works with httpserver and web modules). Supports long sessions. Web is a module that includes the main functions of Tornado (RequestHandler and Application classes), template - managing templates with Python syntax, as well as goodies, like the escape module (methods responsible for encoding / decoding XHTML, URL, JSON and YAML), locale ( localization) and auth — authentication using OpenID and OAuth schemes.
The event was held at an altitude. The speakers covered a fairly wide range of tasks related to the stated topics. It was interesting, communication took place in a relaxed atmosphere. As expected, the public was most interested in discussing and comparing Django with Tornado. The platform goes to a new level, not limited to discussing only Python or Django.
The organizers position Django Meetup as a party where everyone can come and share their work experience, understand what is happening in the industry, get first-hand information (at the 25th meetup, for example, came Sergei Sobko from RBC, who spoke at the 23rd meeting )
I recommend everyone not to miss such events and try to attend, and if possible - to speak. Performing on such venues is a great help for speaking on more serious ones. Great experience and a lot of interesting things.
Special thanks to the organizers for their work in collecting and developing the community.