Lua as a business logic language in high load application. Ilya Martynov ilya@iponweb.net CTO at IPONWEB



Similar documents
MoonGen. A Scriptable High-Speed Packet Generator Design and Implementation. Paul Emmerich. January 30th, 2016 FOSDEM 2016

KVM: A Hypervisor for All Seasons. Avi Kivity avi@qumranet.com

Eloquence Training What s new in Eloquence B.08.00

Using jvmstat and visualgc to Solve Memory Management Problems

In Memory Accelerator for MongoDB

From Firebird 1.5 to 2.5

Hands-On Microsoft Windows Server 2008

Distribution One Server Requirements

Several tips on how to choose a suitable computer

Scalable Data Analysis in R. Lee E. Edlefsen Chief Scientist UserR! 2011

Hardware Recommendations

Technology and Cost Considerations for Cloud Deployment: Amazon Elastic Compute Cloud (EC2) Case Study

Jonathan Worthington Scarborough Linux User Group

With Cloud Computing, Who Needs Performance Testing?

Drivers to support the growing business data demand for Performance Management solutions and BI Analytics

Magento & Zend Benchmarks Version 1.2, 1.3 (with & without Flat Catalogs)

THE BUSINESS CASE FOR HYBRID HTML5 MOBILE APPS

Big Data, Fast Processing Speeds Kevin McGowan SAS Solutions on Demand, Cary NC

CS3813 Performance Monitoring Project

Application Compatibility Best Practices for Remote Desktop Services

Multi-core Programming System Overview

NoSQL Performance Test In-Memory Performance Comparison of SequoiaDB, Cassandra, and MongoDB

GCCSI. Ihr Dienstleister in:

Typical asset: valuable, in a remote position, needs to report events about itself (including failures) and/or it environmnent to the company owning

Input / Ouput devices. I/O Chapter 8. Goals & Constraints. Measures of Performance. Anatomy of a Disk Drive. Introduction - 8.1

Intel Application Software Development Tool Suite 2.2 for Intel Atom processor. In-Depth

EMSCRIPTEN - COMPILING LLVM BITCODE TO JAVASCRIPT (?!)

How Java Software Solutions Outperform Hardware Accelerators

Microsoft Dynamics CRM 2011 Guide to features and requirements

Delivering Quality in Software Performance and Scalability Testing

SAP HANA - Main Memory Technology: A Challenge for Development of Business Applications. Jürgen Primsch, SAP AG July 2011

FileCruiser Backup & Restoring Guide

Tech Tip: Understanding Server Memory Counters

Technical Analysis Document

Virtual Computing and VMWare. Module 4

Tuning WebSphere Application Server ND 7.0. Royal Cyber Inc.

Tempesta FW. Alexander Krizhanovsky NatSys Lab.

PERFORMANCE ENHANCEMENTS IN TreeAge Pro 2014 R1.0

IBM Software Group. Lotus Domino 6.5 Server Enablement

Chapter 7: Distributed Systems: Warehouse-Scale Computing. Fall 2011 Jussi Kangasharju

Virtualization Technologies and Blackboard: The Future of Blackboard Software on Multi-Core Technologies

General Introduction

SCALABILITY AND AVAILABILITY

Measured Performance of an Information System

America s Most Wanted a metric to detect persistently faulty machines in Hadoop

Parallel Computing: Strategies and Implications. Dori Exterman CTO IncrediBuild.

Building Applications Using Micro Focus COBOL

Top 10 reasons your ecommerce site will fail during peak periods

Achieving Nanosecond Latency Between Applications with IPC Shared Memory Messaging

Oracle9i Release 2 Database Architecture on Windows. An Oracle Technical White Paper April 2003

VMware and CPU Virtualization Technology. Jack Lo Sr. Director, R&D

How to choose a suitable computer

How To Analyze Big Data With Luajit And Luatjit

Application-Level Debugging and Profiling: Gaps in the Tool Ecosystem. Dr Rosemary Francis, Ellexus

Application Notes "EPCF 1%' 1SJOU &OHJOF "11&

How To Write A Monitoring System For Free

Restraining Execution Environments

Inside Android's UI Embedded Linux Conference Europe 2012 Karim

Chapter 3 Operating-System Structures

on an system with an infinite number of processors. Calculate the speedup of

Seeking Fast, Durable Data Management: A Database System and Persistent Storage Benchmark

BASICS OF SCALING: LOAD BALANCERS

StACC: St Andrews Cloud Computing Co laboratory. A Performance Comparison of Clouds. Amazon EC2 and Ubuntu Enterprise Cloud

Flash Memory Solutions for Small Business

ntopng: Realtime Network Traffic View

SQL Server Upgrading to. and Beyond ABSTRACT: By Andy McDermid

International Engineering Journal For Research & Development

SAP HANA PLATFORM Top Ten Questions for Choosing In-Memory Databases. Start Here

Updated November 30, Version 4.1

Operating System Software

Choosing a Computer for Running SLX, P3D, and P5

Virtualization. Clothing the Wolf in Wool. Wednesday, April 17, 13

System Structures. Services Interface Structure

4.1 Introduction 4.2 Explain the purpose of an operating system Describe characteristics of modern operating systems Control Hardware Access

Drupal Performance Tuning

3 - Introduction to Operating Systems

Recommended hardware system configurations for ANSYS users

Whitepaper: performance of SqlBulkCopy

Fachbereich Informatik und Elektrotechnik SunSPOT. Ubiquitous Computing. Ubiquitous Computing, Helmut Dispert

Windows Server Performance Monitoring

Web Performance, Inc. Testing Services Sample Performance Analysis

32-bit and 64-bit BarTender. How to Select the Right Version for Your Needs WHITE PAPER

Performance Tuning and Optimizing SQL Databases 2016

Akuda Labs. Leverages Peak Hosting s Operations-as-a-Service Managed Hosting Solution to Process Big Data Analytics 500 Faster without Big Costs

Effective Java Programming. efficient software development

Chapter 6, The Operating System Machine Level

1/20/2016 INTRODUCTION

Solid State Storage in Massive Data Environments Erik Eyberg

Amazon Hosted ESRI GeoPortal Server. GeoCloud Project Report

RevoScaleR Speed and Scalability

In-Memory Analytics: A comparison between Oracle TimesTen and Oracle Essbase

Tomcat Tuning. Mark Thomas April 2009

Chapter 1: Introduction. What is an Operating System?

Monitoring IBM WebSphere extreme Scale (WXS) Calls With dynatrace

Parallels Virtuozzo Containers

AMD PhenomII. Architecture for Multimedia System Prof. Cristina Silvano. Group Member: Nazanin Vahabi Kosar Tayebani

Sawmill Log Analyzer Best Practices!! Page 1 of 6. Sawmill Log Analyzer Best Practices

Mobile Devices - An Introduction to the Android Operating Environment. Design, Architecture, and Performance Implications

Intel DPDK Boosts Server Appliance Performance White Paper

PARALLELS CLOUD SERVER

Transcription:

Lua as a business logic language in high load application Ilya Martynov ilya@iponweb.net CTO at IPONWEB

Company background Ad industry Custom development Technical platform with multiple components

Custom web server One of the components of our technology stack Written in C++ Uses Lua as an embeded scripting language

Adserving requirements High load Complex logic about what ads to show and how to track them Hardware is not always cheaper than developer's time

What is high load

What is high load

How do we come to use Lua? First version of adserver is pure C++ Runs fast Development is slow

How do we come to use Lua? Developers who can write low level code and can write business logic code are rare animals Operational costs: there is a better balance between cost to run and cost to develop

How do we come to use Lua? Separation of church and state C++ for low level and performance critical bits Scripting language for business logic

So what do we use as a scripting language?

Why Lua? So that I can attend Lua workshop as a speaker!

Why Lua?

Game developers like Lua for good reasons Fastest scripting language Easiest to embed scripting language Simple but expressive Can be sandboxed

Why NOT Lua Poor libraries (compared to competition) But this is NOT as big deal for development in special domain (advertising)

Architecture

Multithreaded C++ server Worker thread per CPU core One Lua interpreter state per worker

Multithreaded C++ server Multiple coroutines in each Lua interpreter state New HTTP request new coroutine in idle Lua interpreter state

Sandbox environment Only safe subset of Lua standard library available Special high level IO APIs to access external world Only allow what is really required

Why coroutines Networking IO APIs mean Lua code may wait for responses Coroutines can be paused until response so that we can process other requests meanwhile in worker thread

API design Hide as much complexity from Lua developers as possible

API design example Networking APIs: Allow parallel requests without async or multithreading programming model Separate operations to create requests and to wait for results

API design example

HTTP client API example

Business logic Select ad creative (banner) to show from all ad campaigns Track important evens for ad creative like clicks

Selecting ad creative Complex targeting rules Ad campaign delivery optimization Money calculations

Selecting ad creative

Business data as native Lua data Most of data our business logic works with is read-only Amount of data required in realtime is relatively low Solution: use Lua data structures as in-memory storage

Business data as native Lua data Very natural Lua code it is all just iterations over Lua data structures Very fast you cannot beat in-memory data

Problem with data

Out of memory You cannot share Lua data between Lua interpreter states More CPU cores higher memory usage Projects became bigger too more data

Out of memory: LuaJIT 32 bit Linux 64 bit Linux 64 bit Linux 32 bit application 32 bit application 64 bit application 3 GB of RAM 4 GB of RAM all RAM available but LuaJIT can use only 1GB

Memory problem solution Switch to stock Lua? Not as fast as LuaJIT Fixes immediate problem but with higher memory usage breaks due to GC

Memory problem solution Move business data out of Lua But we need backward compatibility with existing Lua codebases

Attempt #1: userdata userdata + metatables to expose C++ managed data storage as fake Lua tables Each field access via userdata is C function call slow compared to native Lua data

Attempt #2: FFI cdata FFI alternative interface to C code from Lua available in LuaJIT FFI is designed to be LuaJIT friendly cdata is sort of like userdata for FFI also can use metatables to fake Lua tables

How does LuaJIT work? Runs parts of your code as interpreted and parts of it as JIT compiled As long as hot spots are covered you are good If code not written with LuaJIT in mind then most of it will not be compiled

FFI: leap of faith

FFI: leap of faith FFI Lua 1 Lua 2 jit 1.57 1.87 2.00 nojit 55.1 5.05 5.95 3 rd party benchmark source at https://github.com/client9/ipcat/tree/master/lua

FFI: leap of faith If you introduce FFI in your application it will run slower Until you manage to get LuaJIT to JIT compile enough parts of it

How to make LuaJIT happy Use compilation traces to find why code doesn't compile Unfortunately for uninitiated they look like gibberish

Compilation trace

LuaJIT challenge Requires special low level knowledge to make code run fast Sometimes leads to nonintuitive Lua code

LuaJIT quiz

LuaJIT challenge Breaks our abstractions Lua developers forced to work on lower level than normally needed

Wraping up Lua: unique challenges Lua: despite everything very powerful and successful technology