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.

My Delphi STOMP Client is now compatibile with iOS

iOS No Comments »

Thank you to Marco Mottadelli, one of the active contributors to my Delphi STOMP Client open source project.

Now the STOMP client is compatibile with:

  • Delphi Win32/Win64
  • Delphi for iOS
  • FreePascal
It use INDY or Synapse as a TCP library, obviously on iOS you have to use INDY.
Project is on google code.

Sneak peek to simple integration between DMVCFramework and DORM

Uncategorized 3 Comments »

This is a really simple (not optimized and dirty) integration between the upcoming DMVCFramework (WebBroker based MVC framework) and DORM, “the Delphi ORM”.

This is the DMVCFramework controller with the relative mapping and methods. In the method “GetUsers” dorm is used to execute a select to the database using the sanitized parameter passed on the url.

unit UsersControllerU;
  1.  
  2. interface
  3.  
  4. uses MVCFramework, dorm;
  5.  
  6. type
  7.  
  8.   [MVCPath('/users')]
  9.   TUsersController = class(TMVCController)
  10.   strict private
  11.     dormSession: TSession;
  12.  
  13.   strict protected
  14.     procedure MVCControllerAfterCreate; override;
  15.     procedure MVCControllerBeforeDestroy; override;
  16.  
  17.   public
  18.     [MVCPath('/($id)')]
  19.     [MVCHTTPMethod([httpGET])]
  20.     procedure GetUsers(CTX: TWebContext);
  21.   end;
  22.  
  23. implementation
  24.  
  25. uses
  26.   dorm.loggers, dorm.adapters, dorm.Commons, UsersBO;
  27.  
  28. { TUsersController }
  29.  
  30. procedure TUsersController.GetUsers(CTX: TWebContext);
  31. var
  32.   User: TUser;
  33. begin
  34.   User := dormSession.Load < TUser > (CTX.Request.ParamsAsInteger['id']);
  35.   Render(User);
  36. end;
  37.  
  38. procedure TUsersController.MVCControllerAfterCreate;
  39. begin
  40.   inherited;
  41.   dormSession := TSession.CreateConfigured('dorm.conf', TdormEnvironment.deDevelopment);
  42. end;
  43.  
  44. procedure TUsersController.MVCControllerBeforeDestroy;
  45. begin
  46.   dormSession.Free;
  47.   inherited;
  48. end;
  49.  
  50. end.

Now, if you run the application and go to http://localhost/users/1 (the server is running on port 80), you’ll get the following:

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.

RAD Studio XE3 World Tour - Milan, Rome and Dubai

Delphi XE3, Events, HTML5Builder, RAD Studio XE3, bit Time Software No Comments »

Last week I was busy with the event “RAD Studio XE3 World Tour“, held in 3 different cities: Milan, Rome and Dubai. In Milan we had a lot of attendees, the developers were looking forward to see the last RAD Studio XE3 features.

Fabrizio Bitti, opened the event, introducing bit Time Software as italian representative of Embarcadero Techonologies.

I presented RAD Studio XE3 Product Address, Visual LiveBindings and HTML5 Builder with the mobile deploy facilities for Android, iOS and others mobile platforms.

Marco Cantù presented Firemonkey fm2, Windows 8 and the new Metropolis UI showing a lots of demos.

The next day we held the event in Rome, setting the same timing and contents.

The following day I flew, with Fabrizio Bitti to Dubai, where the launch event went live too.

I came back to Rome last night and I’m preparing the materials for the course that I’ll do Oct 16, 17 2012 in Rome.

The course title is “Update to Delphi XE3 from previous versions” and if you are interested in the training, contact me. You can find the topics (in italian and in a bit longer version) here.

Here you’ll find some photos:

Me and Marco while setting up the official RAD Studio XE3 promo video

Me and Marco setting up the official RAD Studio XE3 promo video

Me presenting the new Visual LiveBindings. It is a very cool technology I've been waiting for ages!

Me presenting the new Visual LiveBindings. It is a very cool technology.

Me, talking about the upcoming Mobile Studio for iOS and Android

Me, talking about the upcoming Mobile Studio for iOS and Android

Fabrizio in front of bitTime International Office in Dubai UAE

Fabrizio in front of bitTime International Office in Dubai UAE

See you soon at ITDevCon and DROIDDevCon in Verona.

How to serialize a TList of objects with Delphi

Delphi XE2, Embarcadero, Programming, RTTI, Uncategorized 5 Comments »

Some weeks ago a customer asked to me if it is possibile serialize a TList of objects. “Hey, you should use a TObjectList for this”, I said, but he absolutely needs (I dont know why) of a TList.

This is the (simple) sample code tested with Delphi XE2 Update4. Enjoy.

  1.  
  2. unit Unit4;
  3.  
  4. interface
  5.  
  6. uses
  7.   Winapi.Windows,
  8.   Winapi.Messages,
  9.   System.SysUtils,
  10.   System.Variants,
  11.   System.Classes,
  12.   Vcl.Graphics,
  13.   Vcl.Controls,
  14.   Vcl.Forms,
  15.   Vcl.Dialogs,
  16.   Vcl.StdCtrls;
  17.  
  18. type
  19.   TForm4 = class(TForm)
  20.     Button1: TButton;
  21.     Memo1: TMemo;
  22.     procedure Button1Click(Sender: TObject);
  23.   private
  24.     { Private declarations }
  25.   public
  26.     { Public declarations }
  27.   end;
  28.  
  29.   TPerson = class
  30.   private
  31.     FName: String;
  32.     procedure SetName(const Value: String);
  33.   published
  34.     property Name: String read FName write SetName;
  35.   end;
  36.  
  37. var
  38.   Form4: TForm4;
  39.  
  40. implementation
  41.  
  42.  
  43. uses
  44.   Contnrs,
  45.   dbxjson,
  46.   dbxjsonreflect;
  47.  
  48. {$R *.dfm}
  49.  
  50. procedure TForm4.Button1Click(Sender: TObject);
  51. var
  52.   list: TList;
  53.   m: TJSONMarshal;
  54.   json: TJSONObject;
  55.   p1: TPerson;
  56.   p2: TPerson;
  57. begin
  58.   p1 := TPerson.Create;
  59.   p2 := TPerson.Create;
  60.   try
  61.     p1.Name := 'Daniele Teti';
  62.     p2.Name := 'Peter Parker';
  63.     list := TList.Create;
  64.     try
  65.       list.Add(p1);
  66.       list.Add(p2);
  67.  
  68.       m := TJSONMarshal.Create;
  69.       try
  70.         // Register a specific converter for field FList
  71.         m.RegisterConverter(TList, 'FList', function(Data: TObject; Field: String): TListOfObjects
  72.           var
  73.             l: TList;
  74.             j: integer;
  75.           begin
  76.             l := Data as TList;
  77.             SetLength(Result, l.Count);
  78.             for j := 0 to l.Count - 1 do
  79.               Result[j] := TObject(l[j]); // HardCast from pointer
  80.           end);
  81.  
  82.         json := m.Marshal(list) as TJSONObject;
  83.         try
  84.           Memo1.Lines.Text := json.tostring;
  85.         finally
  86.           json.free;
  87.         end;
  88.       finally
  89.         m.free;
  90.       end;
  91.     finally
  92.       list.free;
  93.     end;
  94.   finally
  95.     p1.free;
  96.     p2.free;
  97.   end;
  98. end;
  99.  
  100. { TPerson }
  101.  
  102. procedure TPerson.SetName(const Value: String);
  103. begin
  104.   FName := Value;
  105. end;
  106.  
  107. end.

The output is, as expected, the following:

  1. {"type":"System.Classes.TList","id":1,"fields":{"FList":[{"type":"Unit4.TPerson","id":2,"fields":{"FName":"Daniele Teti"}},{"type":"Unit4.TPerson","id":3,"fields":{"FName":"Peter Parker"}}],"FCount":2,"FCapacity":4}}

DROIDDevCon - Call4Papers

DROIDDevCon, DROIDDevCon2012, Events, Uncategorized No Comments »

DROIDDevCon is the first conference in italy completly focused on Android OS development.
This post is the official opening for the call4papers!

Dear potential DROIDDevCon speaker,

I’m building the agenda for first DROIDDevCon that will be held October 24th in Verona (Italy).

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)droiddevcon.it.

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

This year topics will be the following:

TOPICS

  • What’s New in Android >= ICS
  • Android Fundamentals
  • Android Core
  • Android Tablets development
  • Android Phone developments
  • OpenSource Frameworks
  • Android and MOMs
  • Android clients for REST or SOAP services
  • Game development & game engines
  • The Android Open Accessory Development Kit (ADK)
  • Backward Compatibility
  • Mobile cross platform development
  • TDD for Android
  • Continuous Integration
  • Testing
  • Android UI Design Patterns
  • Android Best Practices
  • Performance Best Practices
  • NFC
  • NDK (Native Development Kit)
  • Location and Maps
  • HTML5/SVG/WebGL and Android
  • OOD/OOP
  • Metaprogramming
  • Games
  • SOA/ROA
  • Architectures

Target audience

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

The conference web site is http://www.droiddevcon.it.

Are you interested in a specific topic? What do you suggest for DROIDDevCon2012? Let me know

Thanks and see you at DROIDDevCon 2012.

Would you like to partecipate in a conference completely focused on Android development? Come to the DROIDDevCon!

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