Weblog
Niels Hageman: Reliable distributed task scheduling
Niels Hageman talks about Reliable distributed task scheduling, at PyGrunn.
See the PyGrunn website for more info about this one-day Python conference in Groningen, The Netherlands.
I am member of the operations team at Paylogic. Responsible for deployments and support.
Handling taks that are too lengthy for a request/response loop.
Option 1: Celery plus RabbitMQ as backend. Widely used, relatively easy. RabbitMQ proved unreliable for us. Our two queues in two data centres would go out of sync and you needed to reset the queue: manual work and you lose data. This is a known problem. Also, queues could get clogged: data going in but not out.
Option 2: Celery plus MySQL as backend. So no separate queue, just our already running database. But it was not production ready, not maintained, buggy.
Option 3: Gearman (MySQL). Python bindings were again buggy. Could run only one daemon at a time. By default no result store.
Option 4: do it yourself. Generally not a great idea, but it does offer a "perfect fit". We built a minimal prototype, which grew into Taskman.
MySQL as backend: may be fine, but it was not a natural fit. "Thou should not use thy database as a task queue." Polling: there is no built-in event system, though there are hacks that pretend this. Lock contention between tasks is a bit hard. Some options. You can enable autocommit, so you do not need a separate commit. No SELECT FOR UPDATE but simply SELECT. Fuzzy delays. Data growth: queue can grow with time, but you can remove old data.
Task server, daemon with Python and supervisor. Loop: claim task from the database, spawn, sleep, repeat.
Task runner is a separate process. Sets up Python environment where the task runs, it runs the task, does post-mortem: get results, report back.
Task record (database row) simplified: function, positional and keyword arguments, environment, version of environment, state (pre-run, running, ended/finished, ended/failed), return_value.
Task server is an independent application. It does not know about the application that is actually running the tests. Applications need to register to the server with a plugin: methods get_name, get_version, get_environment_variables, get_python_path. Result of task must be a json string.
A task can report progress, by accessing its own instance. So it can say '20% done.' Tasks can be aborted. Task start time can be constrained, e.g. if the task is not started within ten minutes, delete it because this one is not useful anymore. Exception handling.
Taskman properties are optimized for long running tasks, not for minor tasks. Designed for reliability. Tasks will not get lost at some point, they will get executed, and get executed only once. It is less suited for a blizzard of tasks, lots of small tasks, more for heavy database processing. There is no management interface yet. If you must, you can use phpmyadmin currently...
I really want it to be open source, but we have not gotten around to it yet. We first want to add package documentation on how to set it up.
Sylvain Viollon: Tornado and IO in Python 3
Sylvain Viollon talks about Tornado and IO in Python 3, at PyGrunn.
See the PyGrunn website for more info about this one-day Python conference in Groningen, The Netherlands.
I work at MindDistrict. Today I will talk about a web service I built with Tornado. It needs to talk to lots of things, without doing much computation itself. It uses Python 3, because it was about time to use it.
Tornado is a Python web framework and asynchronous networking library, originally developed at FriendFeed.
Tornado is IO loop based. Does not work with a WSGI server. It is easy to implement (micro) web services.
What is an IO loop? Old programming technique, from when threads did not exist or were expensive. It does not use threads, only one flow to execute the code. The loop calls you, you do things, when you are done you relinquish control to the loop. Not efficient for computation intensive tasks.
You can use callbacks, but they are ugly. With generators for the IO loop you can replace them. With @tornado.gen.coroutine you decorate a function and let it yield results.
It works with 'future' objects: a result that still needs to be computed. Comparable with promises in Javascript. You can create them yourself:
def some_function(): future = tornado.concurrent.Future() # do stuff future.set_result(42) return future
Tornado provides an improved version of subprocess.pOpen. Create a future, call the subprocess, when it is done set the return value or an exception.
You cannot use normal threads or file locks. But you can implement a lock mechanism with futures.
Future objects are reusable for caching. 'memoize' type decorators work.
concurrent.futures is part of the standard library in Python 3. With it you can run your heavy computations in a separate process. It works with tornado: create a coroutine and use the Python 3 futures in there. There is a backport for Python 2.7.
Then Python 3. The syntax for generators is much better. Enough support in main packages. It works nice for us in production.
Herman Balsters: Python in Processes, data, contracts
Herman Balsters talks about Python in Processes, data, contracts, at PyGrunn.
See the PyGrunn website for more info about this one-day Python conference in Groningen, The Netherlands.
I am going to talk about modelling. Process modelling and data modelling. My colleague Henk Doornbos will give a more detailed technical talk after this.
Many ICT systems do not work, a lot of projects fail. Dutch government loses about 5 billion euros a year on failed projects. Expected functions are not provided, and offered functionality is not wanted. For example medical patient information systems.
Main cause of failure: the initial design does not match the end-user requirements.
Possible solution: model driven approach (MDA). You can see models as very high level programming constructs. You might think of UML. But let's revisit this.
Wittgenstein: Don't ask for meaning (of data) but of its use.
Our process: start from business process models (our context) and derive data models, mostly automatic.
Validate your models. The only real correctness is end-user correctness. Capture the main requirements from experts. Anyone can write a model, but how do you know it is correct. UML class diagrams are hard to read and write. Instead, we use a structured natural language that is easy to validate by domain experts.
Are the requirements consistent and complete? Go through it in cycles. Do they converge to a stable model? Models are assumptions about how the domain expert would like to do her job. Try to invalidate the model, hunt for false assumptions.
We use business process modeling and notation. Many modeling primitives, of which we have chosen a subset of eight. Process is a collection of pools. Pool has swim lanes for each stakeholder.
Clients learn the notation pretty quickly. We stick as close as possible to the domain expert's language, which may just be Dutch.
High level overview of a process flow:
- You start
- code the input
- process/transform the input
- decode the output
- stop.
Fact-based modeling approach. Get data. We talk about objects and facts. Facts are sentences that are true or false. The European Space Agency uses this approach for their satellites.
Our flavor of that approach is OLE: Object and Logic-based English. Structured natural language. Better suited than graphical models for validation by domain experts. It is very precise and expressive. OLE can be compiled a prototype to pyDatalog for example. From the site: pyDatalog adds the logic programming (think: the prolog language) paradigm to Python's extensive toolbox, in a pythonic way. More about that in the next talk in this room.
An activity may be coded as for example six statements. Activity A is on Date D. Start Event E leads to Statement S. Entity Type T is identified by Number N. Things like that.
We are using this for a contract system. Contracts are built from small initial building blocks. They are combined recursively into a kind of algebra for contracts. That is turned into a pyDatalog program.
The data modeling part is difficult when you are not used to it, but clients can come up with activities themselves and will spot errors in the logic. They may find out that their own process is more difficult than they previously thought. Or they discover that they do it differently than their colleagues.
How good is this when the process later needs to be adapted? We identify which part of the process needs a change. Change the model, compile that part again.
K. Rain Leander: Leveraging Procedural Knowledge
K. Rain Leander talks about Leveraging Procedural Knowledge, at PyGrunn.
See the PyGrunn website for more info about this one-day Python conference in Groningen, The Netherlands.
At RedHat we try to be newbie friendly, because everyone is a newbie in lots of contexts. You specialize in very few fields.
Declarative knowledge: Amsterdam is the capitol of the Netherlands, A is the first letter, etcetera.
Procedural knowledge: how do I get to Groningen, how do I train for a marathon, how do I learn a new language.
So: what versus how.
Example: when you start learning a new programming language, you may want to stick to your trusty editor and version control system instead of switching those at the same time.
I used to dance, had a degree. You do not earn a lot of money that way. I learned languages. Later html, css. I applied, but I usually not even got an interview, because I had a degree in dancing. So I got a degree in computers. I got hired by RedHat.
At RedHat we say "drink from the firehose:" inhale something that is overwhelming. Go with the flow. You have 90 days to pass the exam. It is like a boot camp. It is not about what you do exactly, but how you manage it: do you drown and give up, or do you battle on. So you learn lots of new technologies and after you pass the exam, you apply that knowledge. Not the knowledge about those new technologies, but about how you learned them. You just keep on learning new stuff, and are not afraid of it. No pressure...
For a workshop I setup this Django Girls blog: http://leanderthalblog.herokuapp.com
Challenge: deploy to OpenShift. http://django-leanderthal.rhcloud.com So, it is deployed, but I ran into problems, so you don't really see anything on it. Battling on, challenge still accepted.
Figure out who you are, what you are good at. What programming languages did you learn? How did you do that? Apply that knowledge to new programming languages. Did you learn via tutorials? Readme? Asking others? Reading books, blogs? Just do it and practice, practice, practice? Did it work or not? Apply that knowledge.
On 19 September 2015, there is a Django Girls workshop right here in Groningen. See http://djangogirls.org/groningen/ Free programming workshop for women. We need coaches. Men are welcome too.
On Twitter: rainsdance
PLOG Friday evening report-out
Report-out of the sessions of today, and general report-out (executive super small summary) of the week, at Plone Open Garden Sorrento.
Report-out of today
- Some cleanup tasks for the future identified, fifteen to twenty. Made list of benefits connected to each task. Like: pep8, remove skins usage from core Plone. Risks. Probably setup web page for people or companies to donate money to spend on cleanup, bit like Plone Intranet Consortium. Workers that work for, for example, half the normal wage. Because these are mostly boring tasks, that no one really wants to pick up, not very rewarding of its own. Individual, or group who organises itself. Sponsor can pay you as normal. Do not set up a big organisation. Trust each other.
- Through the web customization, without being horrible. Looked at collective.jbot. Some security issues that need to be considered. That package needs Plone 5 support. ACE editor is useful. Resource folder to add. jbot folder in your diazo theme. Advertise as add-on, not in core, as the approved way to allow these kinds of hacks, with round-tripping. Maybe move to core in the end.
- Increase number of Asian Canadians in Plone. :-) So: diversity meeting. Some are under represented. White males dominate the Plone scene, or at least at the PLOG. But there are some families here, which is very good. Non-native English speakers should feel welcome. At future events, we ask you to look at for newcomers. Connect new people with old-timers. Prioritize first-time speakers at events, help and encourage them. Expand range of talks, like how to run a small business, be a free-lancer. Simple things to make ourselves more attractive to new people.
- Documentation. Explained how we do it.
- Trainings. Three people are willing to give a training at the next conference. Fulvio, Fred, Philip. Beginner, integrator, developer. Master class maybe? Training the trainers. Enable new trainers, tips and tricks, how to set it up and market it. So: we are going to have a Plone Training Team, with me as lead. Increase visibility when people give trainings. Monthly hangouts.
- Translations. Fixed lots of i18n issues. You can start to translate now for Plone 5. We need help figuring out how to extract messages from Javascript.
- Communication with the community. Collection of activity to get into newsletter. Get teams to report regularly and consistently, also about help they may need. Teams should fill out a document about themselves on plone.org. New information in newsletter. Job openings. Recent launches. Contact Christina. Sponsorship. Social media plan, record upcoming events in a calendar. We like to avoid twisting your arm for information that should be shared with the outside world.
- Mosaic is working in Plone 5. Want to do a release this weekend. Alpha release. Various things that do not work yet, but at least you can try it. It changes various things in the rendering engine, like with tiles. Philip: I was mind blown again and again when seeing it today, lost for words.
- Release team. Commit to doing bugfix releases monthly. Let other people release packages. Write nicer combined changelog for each release, more welcoming, more exciting for new developers.
- Plone RESTapi. Created package to use http verbs in the ZPublisher, delegating to browser views. plone.restapi can build on top of that.
General report-out of this week
- Cleaning up bits of the backend, like portal skins, tools, and also simply pep8.
- RESTapi, preparation for frontend.
A bit scary at the beginning of the week, complaining about what does not work, or all the big work that still needs to be done. But there is a plan for the long term future, with sane steps for short and middle term. So rough roadmap is possible and totally compelling. More energy for people who contribute. We can be brave for the next five years, to see a brighter future.
Big cheer for everybody!
Tomorrow: overflow day. You can have more discussions. Or visit Sorrento or other bits of the surroundings. Paul will start compiling some documents in a kind of roadmap, and people are invited to help. Open space about Plone booth at Bilbao. Plone RESTapi.
Maurizio: the board really helped this year, with declaring this a Strategic Summit, and helping in organizing. Thank you all!
[Image by Fred van Dijk.]