Book Review: “ZeroMQ” (PACKT Publishing)

Delphi XE, Delphi XE2, Delphi XE3, Delphi XE4, Embarcadero, Programming, RAD STUDIO XE 2 Comments »

Introduction

Some days ago I was contacted by a representative from PACKT Publishing asking me to write a review for their last book about the ZeroMQ library.

ZEROMQ BOOK COVER

ZEROMQ BOOK COVER

In 2009 I was looking for a fast, very fast, messaging system for a complex project and I meet ZeroMQ. At that time there was the 1.x version and I wrote a Delphi wrapper for the C dll that some days later has been included in the official ZeroMQ distribution.

Now, after 4 year since then, I’m using ZeroMQ for a lot of things. I’ve talked about ZeroMQ to the popular ITDevCon (The European Delphi Conference), so I’m very happy to write about ZeroMQ another time.

So, back to the book review…

The book title is simply “ZeroMQ”, but the subtitle explains what you’ll really learn from it: “Use ZeroMQ and learn how to apply different message patterns”.

Yes, this book is really a crash course in ZeroMQ. In about 100 pages, this “small but full of interesting things” book, explains all the most useful message patterns implemented in ZeroMQ. Congrats to Faruk Akgul (the author).

Traditional message queuing systems use a broker. However, ZeroMQ is brokerless. In a brokerless design, applications can directly communicate with each other without any broker in the middle. All the complexity is hidden, and handled, by ZeroMQ. In this situation there isn’t the “single point of failure”. In some cases this architecture cannot be used, but when it can be, you can gain a lot of flexibility, speed with no added complexity.

Let’s give a more  deeper overview for each chapter.

Chapter 1: Getting Started

In this chapter there are some informations about the messaging architectures in general (good for newcomers to the topic) and about ZeroMQ messaging (in particular). Some concepts introduced in this chapter are reused a lot in the rest of the book.

In chapter 1 is introduced the first and the simpler ZeroMQ pattern, the request-replay.

Chapter 2: Introduction to Socket

This chapter starts with a nice introduction to the publish-subscribe pattern and the related filtering (ZeroMQ can filter messages with a very simple “match” pattern). Then, the chapter talks about one of the most interesting patterns when speed is important: the pipeline pattern. While is talking about the pipeline, it explain the ZMQ_PULL and the ZMQ_PUSH socket types. At the end of the chapter, there is an introduction to the Valgrind’s tools suite to detect memory leaks in C/C++ programs. In Delphi can be used FastMM or other similar tools for the same thing.

Chapter 3: Using Socket Topology

In this chapter there is a small introduction to the types of Internet Sockets and TCP. There there is a nice comparison between the “plain” sockets and the ZeroMQ sockets.

At the end, there is an introduction to the CZMQ, a small helper library which lets

C developers to code their ZeroMQ applications easier and shorter. For a Delphi programmer there are a number of ZeroMQ wrapper that makes its use really a snap.

Chapter 4: Advanced Patterns

In this last chapter, are introduced some advanced variation of the previously introduced patterns. Then, there is a nice explanation of some critical situations that could happened in a messaging system. To help the programmer to handle this cases there a number of examples of the ZeroMQ “High Watermark” setting. As very last topic, there is a well known problem, the infamous “slow subscribers in a publish-subscribe pattern”.

Conclusions

The “ZeroMQ” book published by PACKT Publishing is a small but very nice book. Can be very useful to all those people that don’t know about messaging or want add the power of ZeroMQ to their messaging knowledge.

As in every single thing, there are good aspects and bad aspects.

This book is good for an introduction but is not so good for advanced users. There are some other ZeroMQ patterns and features that are not explained at all. However, these patterns are not the most used, or are advanced stuff, so this could not be a big issue.

Considering, the price, the contents and the informative density, is a definitely a good book that can be read, and studied, in few hours and could change your way to do things in everyday programming (messaging are very often not used, or used in a bad way, simply because usually is complex to write and maintain a good messaging system).

One of the more nice features about ZeroMQ is that it can use different transportation protocols. The same library and the same code can be used to do messaging between machines, between processes or between threads in the same process (ipc). As last note, ZeroMQ can handle, without much effort, millions of messages per seconds. If you need speed… consider this.

P.S. I’ll translate and publish on this blog, some of the C examples contained in the book, in Delphi. Stay tuned.

#3 “dorm, the Delphi ORM” bullettin

Uncategorized, dorm No Comments »

A veeery log time after the last dorm bullettin. But, as usual, I was been very busy on some projects (not only dorm) and the time goes by…

However, dorm has been extended, polished and improved over the last few months. Has been used in a couple other projects in my compoany (www.bittime.it).

So, here’s a small list of improvements and some other tips:

- ObjStatus support (more to come)

- TdormSession non-visual component. Check “\samples\DelphiXE3\TdormSession_Sample01\formSample1.dproj”

- dorm is now in Continuous Integration (not for all supported databases, but I’m improving that)

- I’m integrating a JSON/DataSet/ObjectList mapper into dorm to be used in RESTful DataSnap/WebBroker (or not) http servers. More to come.

- Delphi XE3 Support

- Removes SuperObject as external lib. Now dorm uses an internal patched version.

- More demos added (Most noticeably id under “\samples\DelphiXE3\TODOManager\TODOManager.dproj”)

- Added samples using the new Visual LiveBinding feature in Delphi XE3

About the ObjSupport it’s worth to spend some words about it.

Since the beginning, dorm is completely “perisstence ignorant”: In other words, you can persiste what you want, you dont need to inherit from a specific class or implement a specific interface. This is a very powerful feature but make some internal dorm mechanism very complex. But I really WANT to have this feature, so I’ve added another “mode” to work with dorm: ObjStatus.

If dorm engine finds a property nemed “ObjStatus” of a specific type, it’ll use that property to track the object status (Clean, Dirty, Deleted).

In this way, I gained a *LOT* of speed compared to the prior version regarding persistence of complex objects graph.

eg.

procedure DoSomethingOnPersonByID(ID: Integer);
var
  p: TPerson;
begin
	p := Session.Load(ID);
	p.FirstName := 'Daniele';
	p.Car.Model := 'Civic';
	p.Phones.Add(TPhone.Create('555-555-33-22', 'Home'))
	Session.Persist(p); //generates insert, update, delete for related objects too
	p.Free;
end;

As Usual you can find the project code here https://code.google.com/p/delphi-orm/

DataSnap XE3 concurrency problems and Update1

Delphi XE3, Embarcadero, Uncategorized 4 Comments »

If you know DataSnap, probably you know the famous post by Roberto Schneiders about its stability problems (http://robertocschneiders.wordpress.com/2012/11/22/datasnap-analysis-based-on-speed-stability-tests/).

Now, after some (right) dust cloud, in the Update 1 Embarcadero fixed some bugs.

I still haven’t the time to do an heavy test but the first “fast-and-dirty” test give some results, and I’d like to share my little tests.

I created a simple “DataSnap REST Application” as a VCL Application.

Start a little test with ApacheBenchmark (you can find it in the Apache HTTPD installation directory).

Run the test… and, exception at the 32° connections, just as before the update. However this is not a “bug”, it is simply a problem related to the default wizard configuration.

So I changed the MaxConnection to 1024. This number is very high (for a simple PC) but I’m interested in the concurrency problems, so I’ve to push the concurrency far enough to che the Update 1 Fixes.

MaxConnections

MaxConnections

Also, I’ve disabled the session with a little change in the “EchoString” method (as suggested by Marco Cantù in his blog post about DataSnap problems).

Closing the session

Closing the session

Now the test results are good. As I said, my objective is not to check the performance or other problems arised from the Roberto tests. My test is just about the concurrency problems (IMHO the biggest one) and the related crash.

Here the Apache Benchmark tests with 100000 requests with 100 concurrent connections.

D:\wamp\bin\apache\apache2.2.22\bin>ab -v 1 -n 100000 -c100 http://127.0.0.1:8080/datasnap/rest/TServerMethods1/EchoString/Daniele
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
Completed 40000 requests
Completed 50000 requests
Completed 60000 requests
Completed 70000 requests
Completed 80000 requests
Completed 90000 requests
Completed 100000 requests
Finished 100000 requests

Server Software:
Server Hostname:        127.0.0.1
Server Port:            8080

Document Path:          /datasnap/rest/TServerMethods1/EchoString/Daniele
Document Length:        22 bytes

Concurrency Level:      100
Time taken for tests:   465.320 seconds
Complete requests:      100000
Failed requests:        0
Write errors:           0
Total transferred:      18966732 bytes
HTML transferred:       2200000 bytes
Requests per second:    214.91 [#/sec] (mean)
Time per request:       465.320 [ms] (mean)
Time per request:       4.653 [ms] (mean, across all concurrent requests)
Transfer rate:          39.81 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1  11.8      0     529
Processing:     2  464 230.4    500    2041
Waiting:        1  457 216.6    499    1922
Total:          2  465 230.8    501    2041

Percentage of the requests served within a certain time (ms)
  50%    501
  66%    565
  75%    609
  80%    637
  90%    699
  95%    769
  98%   1008
  99%   1039
 100%   2041 (longest request)

I certainly will do other tests, however this fast-and-dirty test gave me a good impression.

More to come.

ITDevCon 2012 – RECAP

Delphi XE3, Embarcadero, Events, HTML5Builder, ITDevCon, ITDevCon2012, Programming, bit Time Software 2 Comments »

Last friday is just ended the 4th edition of ITDevCon. This conference is, now, the biggest Delphi conference in Europe, in terms of speakers, speeches and topics… no doubt!

Some numbers:

  • 2 days
  • 31 speeches
  • 15 speakers from all over the world (Italy, USA, Norway, Slovenia, Benelux)
  • 70 attendees c.a. from all over the world (Italy, Germany, Russia etc)
  • 32 prizes offered by our (beloved) sponsors. No one of the attendee went back home without some prize won. In many cases the price of the prize has been even bigger than the price of the ticket!

Some speakers, attendees and other people, have already blogged about the conference and many others have talked about it on twitter and facebook. There’s been a great partecipation… before, during and after the conference.

#itdevcon on twitter: https://twitter.com/search?q=%23ITDevCon&src=hash

http://edn.embarcadero.com/article/42634

http://www.thedelphigeek.com/2012/10/itdevconrecap.html

http://www.thedelphigeek.com/2012/10/itdevcondinner-in-verona.html

http://blogs.embarcadero.com/pawelglowacki/2012/10/28/39863

http://www.thedelphigeek.com/2012/10/itdevcon-photos.html

http://blog.talentgarden.it/2012/07/24/itdevcon-tag-mediapartner-della-conferenza-per-sviluppatori-delphi/

http://www.hubme.in/events/europe/italy/itdevcon-european-delphi-conference-2012-san-giovanni-lupatoto-verona

http://www.marco.breveglieri.name/blog/?tag=itdevcon

http://blog.marcocantu.com/blog/conferences_itdevcon_2012.html

ASAP will be published other photos on Google Picasa.

This year too, ITDevCon has been a great experience.

I want to say THANK YOU to all the speakers, attendees and sponsors. And also to all the great bit Time crew that makes this conference the biggest Delphi conference in Europe. As you may think, I’m very proud of it.

See you next year for ITDevCon 2013!

How to enable HTML5 Application Cache (offline webapp) on a DataSnap based web server

Uncategorized No Comments »

By default, stadalone WebBroker DataSnap servers do not allow to use the “new” HTML5 Application Cache file manifest.

While I was preparing the contents and the demos of my “HTML5 and DataSnap web application development” (with more than 250 slides and more than 50 samples. More info here) I’ve configured the DataSnap components to support this HTML5 feature.

There is only one change to do to the default “REST WebApplication” generated by the wizard.

In the WebModuleUnit there is the TWebFileDispatcher component used to deliver static (or “not-so-static” files like the javascript proxy) to the client. This component has the property WebFileExtensions that is a collection of key-value containing all the allowed file extensions with the related mime-type.

The following screenshot shows which is the change to do.

Add "appcache" extension with the "text/cache-manifest" mime-type

Add

Add “appcache” extension with the “text/cache-manifest” mime-type.

Now your DataSnap server is ready to be an HTML5 compliant WebServer. Tested on Delphi XE3.

More info about the HTML5 Application Cache here.

Guest speaker @ Delphi Develpers Days in Rome

Uncategorized No Comments »

Next week I’ll be the guest speaker at the Delphi Developers Days held in Rome by (and with) Marco Cantù and Cary Jensen. Marco and Cary are very good speakers and very expert developers, so will be nice to be there with them and I want to thank them for inviting me.

My talk will be on May 17 and these are the details:

Title

Improving Code Testability Through Dependency Injection

Abstract

Create a highly decoupled system is not simple. Inversion of control principle help to understand what you have to do to accomplish this target. In this speech I’ll introduce the reasons behind the adoption of a IoC is a good thing for your software and your business. In the final part, will be introduced the dependency injection container contained in the Delphi Spring Framework (spring4d). There will be lot of examples to help to correctly understand this “new & better” way to do old things.

This is the page for register to the event

http://www.delphideveloperdays.com/#rome

See you there!

ITDevCon2012 - Call4Papers

Events, ITDevCon2012, Programming, bit Time Software No Comments »
ITDevCon2012

Dear potential ITDevCon speaker,

I’m building the agenda for next ITDevCon 2012 that will be held October 25th,26th in Verona (Italy), the same location of the past year.

The call for papers are officially open right now, so if you want to propose some speeches, I’ll be glad to see it.

As usual, for the Call4Paper I need:

  • Title (for every talk)
  • Abstract (for every talk)
  • Difficulty level (for every talk. Difficulty level is a scale from 1 to 3 with the following mean: introduction, intermediate, advanced)
  • Speaker’s photo
  • Speaker’s profile

I’m looking forward to your proposal. The call4papers ends at July 31st, 2012.

Send your proposal to call4paper(at)itdevcon.it.

Proposals will be evaluated and the speakers will be contacted ASAP.

This year topics will be the following:

TOPICS

  • What’s new in Delphi
  • FireMonkey
  • iOS development (iPhone, iPad, iPod Touch)
  • MacOSX development
  • Android clients for Delphi servers
  • Windows 8
  • Delphi best practices
  • Design Patterns
  • DataSnap
  • “Unusual” Delphi markets
  • TDD and Unit Tests
  • Agile methodologies
  • Dependency Injection
  • ORM
  • Software engineering
  • “Hands on” sessions for the most used Delphi frameworks (e.g. Delphi Spring Framework, OTL etc)
  • Mobile
  • HTML5/SVG/WebGL and Delphi
  • OOD/OOP
  • Web development with Delphi
  • Real OOP Delphi applications developments
  • Delphi fundamentals/advanced
  • Metaprogramming
  • Games
  • SOA/ROA
  • Architectures

Target audience

  • Software architects
  • Software developers
  • Project managers
  • IT managers
  • Trainers

The conference web site is http://www.itdevcon.it (2012 version is still under construction).

Do you want to see a particular topic or have a suggestion for ITDevCon2012? Let me know

Thanks and see you at ITDevCon 2012.

P.S. This year, ITDevCon will be even more amazing! Stay tuned!

Delphi MVC Web Framework - “Hello World”

Delphi XE, Delphi XE2, Design Patterns, Embarcadero, MVC, RTTI, dorm 6 Comments »

This is the first “Hello World” for my Delphi MVC Web Framework.

  1.  
  2. program DelphiMVCWebFramework;
  3.  
  4. {$APPTYPE CONSOLE}
  5.  
  6. uses
  7.   System.SysUtils,
  8.   MVCEngine in 'MVCEngine.pas',
  9.   BaseController in 'BaseController.pas';
  10.  
  11. var
  12.   mvc: TWebMVCEngine;
  13. begin
  14.   mvc := TWebMVCEngine.Create;
  15.   mvc.AddRoute('/', procedure(Context: TWebContext)
  16.     begin
  17.       Context.Write('Hello World');
  18.     end).Start(8080);
  19.   ReadLn;
  20.   mvc.Free;
  21. end.

Features list (some of them are in the internal roadmap)

  • Completely MVC
  • Addressable with servername/controllername/actionname?par1&par2
  • Addressable with servername/controllername/actionname/par1/par2
  • Can also use anonymous methods as actions for very simple app (in the sample)
  • Really RESTful (Level 3 of the Richardson Maturity Model)
  • Fully integrable into WebBroker and DataSnap
  • Supports multiple resource rapresentations
  • Completely customizable routing using internal formatting or regex
  • Inspired to ASP.NET, Sinatra, Java Spring MVC, Java Restlet
  • Scriptable views support (Pascal, Razor, Lua)
  • Component based
  • Session support
  • ORM support using dorm
  • Classic TDataSet support
  • State server to support real loadbalancing using reverse proxy
  • Can be deployed as standalone (in the example), ISAPI dll and Windows Service
  • Fully support https
  • More to come…
  • This framework is still under development.

    Are you interested in? :-)

#2 “dorm, the Delphi ORM” bullettin

Uncategorized, dorm 3 Comments »

This is the second post regarding a fast update on the last changes to the dorm project in terms of management and code.

  • Welcome to 2 new contributors: Marco Mottadelli and BraveCobra (this is the full list http://code.google.com/p/delphi-orm/people/list)
  • Added 2 new PersistentStrategy for MSSQLServer based on dbExpress (the 1st use the Embarcadero dbExpress driver, while the 2nd use the DevArt dbExpress driver)
  • Added another PersistentStrategy for MSSQLServer based on ADO (so also Delphi Professional users can use dorm with MSSQLServer)
  • The new mapping strategy is under development. There will be “3 levels” of mapping: Config File, RTTI Attributes and “Conventions Over Configuration” (CoC) (do you wanna check the code in dev branch? Click here)
  • Added more unittests
  • Roadmap updated
  • Introduction to dorm, now is a PDF document
  • The config file has been splitted in “Persistence” and “Mapping” for a more flexible configuration
  • Added packages (Thank you BraveCobra)
  • Added MappingCreator. Now you can create the mapping file using an existent database.
  • IWrapperList (a duck typed list) now is used EVERYWHERE! You can use whatever list from whatever library you want to use. The list must have only a specific methods named as following: Add, Clear, GetElement/GetItem, Count
  • Added FillList methods
There are plenty of new features still to come. Stay tuned!

Do you wanna see an enormous potential tool? Here’s the pascal for Java and Android

Programming 15 Comments »

Yes, this is very cool. I’m not a Java hater, in terms of language (and I dont want to start a language-war), but some Java features, IMHO, are a bit uncomfortable for me.
However, Java is very powerful and there are an enormous amount of good open source project for Java. So, seeing java libraries used in simil-pascal code (is not Delphi’s Pascal, but enough similar), is nice. In this way, you can use all the java libraries in Pascal!
I’d like to have this integration in Delphi IDE too with a good designer for Android activities.

I’m testing Oxygene for Java (form RemObjects) for a couple of things, specifically Android related.
This is my first console project in Oxygene for Java, just to see some code.

Oxygene for Java - Simple console app using specific Java libraries

Oxygene for Java - Simple console app using specific Java libraries

IMHO there is an enormous potential for the Delphi developer and for all the developers that need a unique language to do server, mobile and native ultra fast app.

I dream to have this technology into the Delphi IDE.

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in