Murex PPT template
Download
Report
Transcript Murex PPT template
OUR JOURNEY
TO C++
Cosmin Cremarenco – Principal Software Engineer
A FEW WORDS ABOUT MUREX
•
COMPANY FOUNDED IN 1986
•
FRONT/MIDDLE/BACK OFFICE
•
WINDOWS/LINUX/SOLARIS/AIX/HP-UX
•
BIG MONOLITHICAL EXECUTABLE
•
LOC
• C 10M
• C++ 4M
• Java 7.5M
© 2015 Murex S.A.S. All rights reserved
2
THE ARCHITECTURE IN THE BIGGER LINES
A classical three tier architecture
Fat Client
(Java Swing)
XML
JVM
MX, Logic Tier
Database
Don’t put a JVM inside your exe!
© 2015 Murex S.A.S. All rights reserved
3
JOURNEY TO C++
Obstacles
LEGACY CODE
•
•
Existing legacy somewhat-object-oriented system MEF (Murex Extension Framework)
•
COMPILERS AND SUPPORTED PLATFORMS
•
BUILD SYSTEM
•
INTER-LANGUAGE SERIALIZATION
© 2015 Murex S.A.S. All rights reserved
4
MEF
HOW TO DO OBJECT-ORIENTED PROGRAMMING
… when you can’t (won’t) use C++
Why not C++
• C++ compilers not all up to notch on all platforms (early 2000)
• While C had better support
• Most engineers familiar with C, not so much with C++
• Opportunity to add some functionality available in other languages
like Java?
© 2015 Murex S.A.S. All rights reserved
6
MUREX EXTENSION FRAMEWORK (CONTD)
MEF is based on pre-processing C files providing:
• Object-oriented programming (inheritance, polymorphism etc.)
• Dynamic Class Loading
• Reflection
• Dynamic Invocation
• Serialization
All modeled closely on the JAVA APIs
© 2015 Murex S.A.S. All rights reserved
7
MUREX EXTENSION FRAMEWORK
The pre-processing phase
Attribute.h – handwritten code
Attribute.r – handwritten code
struct mxSystemIATTRIBUTE
{
const char* (*GetValue)(mxSystemIATTRIBUTE* pxThis);
void (*SetValue)(mxSystemIATTRIBUTE* pxThis, const char* szValue);
};
struct mxSystemATTRIBUTE
{
char* m_value;
};
MEFC
mef/Attribute.c – generated code
Attribute.c – handwritten
static const char* GetValue(mxSystemIATTRIBUTE* pxThis)
{ return pxThis->m_value; }
static void SetValue(mxSystemIATTRIBUTE* pxThis, const
char* szValue)
{ pxThis->m_value = strdup(szValue); }
#include “mef/Attribute.c”
static mxSystemIAttribute* New()
{ return (mxSystemIAttribute*)malloc(sizeof(mxSystemIAttribute)); }
static const char* GetValue_wrapped(mxSystemIATTRIBUTE* pxThis)
{ return OBJECT_TABLE(pxThis)->GetValue(pxThis); }
static void SetValue_wrapped(mxSystemIATTRIBUTE* pxThis, const
char* szValue)
{ OBJECT_TABLE(pxThis)->SetValue(pxThis, szValue); }
static void Destroy(mxSystemIAttribute* pxThis)
{ free(pxThis); }
© 2015 Murex S.A.S. All rights reserved
8
MUREX EXTENSION FRAMEWORK (CONTD)
Let’s say we now wanted to use our mxSystemIATTRIBUTE object:
mxSystemATTRIBUTE* attribute = mxSystemIATTRIBUTE->New();
mxSystemIATTRIBUTE->SetValue(attribute, “some value”);
mxSystemIATTRIBUTE->Destroy(attribute);
Allows
runtime query
and
introspection
Object layout in memory:
CLASS PTR
New
MEF TABLE PTR
GetValue FuncPtr
SetValue FuncPtr
char* m_value
Class Name
Method Names and
parameter types
© 2015 Murex S.A.S. All rights reserved
9
MUREX EXTENSION FRAMEWORK (CONTD)
Drawbacks
• No type safety – assign to void*
• Verbose
• Outdated memory management
• Sneaky implicit run-time dependencies
• Not standard (steep learning curve for beginners, doc absence…)
© 2015 Murex S.A.S. All rights reserved
10
GET FROM MEF TO C++
• Get rid of the MEF header
• Tuck it into a base class MefObject – replacing void*
• Use std collections
• Transform all MEF inheritance to C++ inheritance
• Rely on Reflex and castxml for C++ introspection
• Remove the hand-written function pointer struct
• Use clang-tidy to check for violations (casts, etc)
© 2015 Murex S.A.S. All rights reserved
11
C++ COMPILERS
C++ COMPILERS
Murex needs to support a good number of platforms
• Windows, Linux, Solaris X86/SPARC
• Dropped support for AIX and HP-UX
C++ compilers come with their own quirks and bugs
© 2016 Murex S.A.S. All rights reserved
13
SUN STUDIO 12.4
… while migrating to C++11
Broken RVO support
© 2016 Murex S.A.S. All rights reserved
14
SUN STUDIO 12.5
Delete operator confusion
© 2016 Murex S.A.S. All rights reserved
15
BUILD SYSTEM
BUILD SYSTEM
… what do you use to build large amounts of code?
Don’t do this
nowadays!
Started our own with a legacy “make”-like system
• Make has its own quirks and different dialects (ie. nmake on
Windows)
Our system tweaked for our use
• Remember monolith? The VS linker would take 15’ to link final
executable
• Resorted to splitting executable in a bunch of mutual dependent
.DLLs
© 2016 Murex S.A.S. All rights reserved
17
BUILD SYSTEM (CONTD)
CMake seems nice
CMake generates .sln/.vcproj/Makefiles from CMakeLists.txt
• Excellent integration with IDEs
• Ctest
But:
• CMake is sloooooow on our codebase – 10 – 15’
• Needed every time we add/remove files
• Wouldn’t advise its use today
Other options: GYP, Blaze
© 2016 Murex S.A.S. All rights reserved
18
SERIALIZATION
SERIALIZATION
Or how to get your data to Java in a modern way
• MEF serializes into XML then sent to Java
• Constraints on latency and through-put made us go to binary
serialization
• Enter Murex Object Serialization
• Works mostly like Protocol Buffers/Thrift/others
• But:
•
•
•
Supports inheritance
Wealth of collection types: map/set/vector
Nested collections
© 2016 Murex S.A.S. All rights reserved
20
MOS PERFORMANCE BENCHMARK
Smaller is better
Smaller is better
avro-generic
avro-specific
thrift
thrift-compact
protobuf
java-manual
wobly-compact
ser
wobly
deser
kryo-serializer
kryo-flat
kryo-flat-pre
kryo-opt
kryo-manual
mos
0
1000
2000
3000
4000
5000
6000
mos
java-built-in
java-built-in-serializer
ser
xml/xstream
json/org.json/manual-tree
deser
jboss-serialization
json/json.simple/manual
0
10000
20000
30000
40000
50000
60000
70000
© 2016 Murex S.A.S. All rights reserved
21
SOME LESSONS
… which we learned the hard way
Strive for standard off-the-shelf languages and tools
•
•
Not everyone is Google and Facebook
Essential!
The build is as important as the code
•
•
Profit from the wealth of open source projects
•
Blaze sounds good!
Multi-platform software is as C++ compliant as its less compliant target
•
•
Easier if you just target Linux
•
LLVM tools can greatly help with migrating (see clang-tidy)
•
Introspection in C++ can be done and can be useful (see CastXML)
© 2016 Murex S.A.S. All rights reserved
22
THANK YOU!
@WORK_AT_MUREX
@CCOSMIN
PARIS
Cosmin Cremarenco
8 rue Bellini
75782 Paris cedex 16
FRANCE
Tel + 33 1 4405 3200
linkedin.com/company/murex
https://twitter.com/work_at_murex
www.murex.com
[email protected]