DataSnap Filters Compendium Updated to Delphi 10 Seattle

Very quick info.

Not tremendous useful today as when developed (Delphi 2010 time frame) but, if someone is still using my DataSnap Filters Compendium (and I know some users heavily use it), now can find the Delphi 10 Seattle version on github. Currently works all the speed test and the server/client test. Consider this as a very stable beta.

Here’s the project repository

https://github.com/danieleteti/dsfc

DataSnap XE3 concurrency problems and Update1

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.

Max Connections
Max Connections

 

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:wampbinapacheapache2.2.22bin>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.

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

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.

App Android ITDevCon2011 disponibile sul Market (ITALIAN)

Manca solo una settima all’inizio di ITDevCon2011. Per permettere a tutti gli iscritti (e far decidere chi è ancora indeciso) di sfruttare al meglio i due giorni di intensa formazione, abbiamo appena pubblicato l’applicazione ITDevCON2011 sul’Android Market.
Trevete il programma completo della conferenza, i profili degli speaker e informazioni sugli sponsor.
Inoltre, potrete definire i vostri speech preferiti in modo da essere avvisati subito prima dell’inizio dello speech.
Potrete votare e commentare ogni speech. Potete commentare da subito inserendo le vostre aspettative per lo speech o alcune delucidazioni sul contenuto. Il voto invece sarĂ  possibile solo a speech avvenuto.

Dal punto di vista tecnico, questa applicazione Android utilizza un servizio REST scritto con Delphi utilizzando DataSnap e i Mobile DataSnap connectors per Android.
Per chi fosse interessato al “Making”, durante la conferenza potrà assistere allo speech di Salvatore Sparacino che illustrerà i vari step dello sviluppo e le soluzioni tecnologiche adottate.
Per definire il vostro profilo, votare e commentare, dovrete utilizzare il codice fornito al momento dell’iscrizione. Se non siete partecipanti, o ancora non vi è arrivato il codice di accesso, potete utilizzare l’applicazione come “anomymous”. In questo caso non potrete salvare i vostri speech preferiti Né votare o commentare.

Dashboard

La time table
Speaker details
Dettagli dello speaker (in questo screenshot, DavidI)

Il link da dove installare l’applicazione è il seguente:
https://market.android.com/details?id=it.bittime.itdevcon2011

Happy ITDevCon2011

ITDevCon2011 Android App

In less that a week, ITDevCon2011 will begin. To allow all members (and to let decide who is still undecided) to take advantage of the two days of intense training, we have just published the application ITDevCON2011 on the Android Market. You’ll find full conference program, speaker profiles and information about the sponsors.
In addition, you can define your favorite speeches in order to be alerted immediately before the start of the speech.

You can vote and comment every speech. You can comment now by entering your expectations for the speech or some clarifications on the content. The vote, however, is allow only after the speech.
From a technical standpoint, this Android application uses a Delphi DataSnap REST service and the DataSnap Mobile Connectors for Android.

For those interested in the “Application Making Of” during the conference may attend the speech of Salvatore Sparacino illustrating the various steps of development and the technological solutions adopted. Very cool! Salvatore will talk about a REAL app, not only a demo!

To define your training profile, add rates and comments, you have to use the code provided at registration. If you’ll not attend, or you have not received your access code, you can use the application as “anomymous.” In this case, you cannot save your favorite speeches or votes or comments.

Dashboard

The time table
Speaker details
Speaker details (here DavidI)

The link to install the application is as follows:
https://market.android.com/details?id=it.bittime.itdevcon2011

Happy ITDevCon2011!

DataSnap Mobile Connectors in RAD Studio XE2

WARNING! I’ve been authorized by EMBARCADERO to write about RAD Studio XE2.

RAD Studio XE2 is full of nice and exciting features. One of the most interesting IMHO is the DataSnap extension called “Mobile Connectors”.

In the past, I’ve talked about connecting and using your datasnap REST service with Android, creating ad-hoc json messages and manually parsing the returned json messages. With RAD Studio XE2 this is no longer needed. If you have a DataSnap REST service, you can automatically generate the proxy connector for the major mobile platforms. Yes, just like you have been doing with Delphi or C++ since Delphi 2010.

DataSnap XE2 version supports 4 mobile platforms:

  • Android (Using Java)
  • BlackBerry (Using Java)
  • Windows Phone (Using C#)
  • iOS 4.2 (Using ObjectiveC)

If you want to enable your DataSnap server for the Mobile Connectors you have to explicitely check the feature in the “New DataSnap Server” wizard.

The generated proxies support all the standard Delphi types and maps them to the native target language. Some of the most used Delphi types (e.g. TStream, TDBXReader and so on) have been rewritten in the target language to allows a greater compatibility and a simpler programming interface. The functionalities of the various Delphi classes are not-one-to-one with the Delphi version, but  similar.

From a remote (or local) machine you can download the generated proxy and all the required files using a tool called “Win32ProxyDownloader.exe” which is in the bin folder of your RAD Studio installation. In my FieldTest version, this tool called without parameters, shows its help.

As usual you should have the RAD Studio bin folder in your PATH environment variable, so you can change your current directory to where you want the proxy and write this command in a commandprompt window:

Win32ProxyDownloader -language java_android -host localhost:8080

The proxy and all the needed files are ready in the current directory.

Mat DeLong wrote a very nice Eclipse plugin to use the proxy downloader directly from Android or BlackBerry development environment. You can find this plugin here.

You know that Android is my preferred mobile platform, don’t you?

So, let’s go with an Android example.

To use the generated java proxy, in an Android client application I can write something like this:

//Create the connection
connection = new DSRESTConnection();
connection.setHost("10.0.0.2");
connection.setPort(8080);
connection.setProtocol("http");
//Create the proxy
proxy = new DSProxy.TServerMethods1(connection);
//Use a simple remote method
int sum = proxy.Sum(1,4));
//Use a complex remote method
TStream inStream = null;
TStream outStream = null;
String s = "abc";
inStream = new TStream(s.getBytes());
outStream = proxy.DoSomethigWithATStream(inStream, sum, "Hello DataSnap Mobile Connectors");
//here I can use the java TStream type

All the custom Delphi types (e.g. TPerson) are mapped on the target platform as TJSONObject. All the TJSONValue hierarchy has been ported, with a very similar interface, to the target platform as a wrapper of the native JSON classes.

So, you can write code as the following (Java on Android):

TJSONObject jobj = new TJSONObject();
jobj.addPairs("firstname", "Daniele");
jobj.addPairs("lastname", "Teti");
jobj.addPairs("age", 31);
jobj.addPairs(new TJSONPair("nickname", new TJSONString("Spiderman")));
if (jobj.has("firstname"))
  doSomethingWithFirstName(jobj.getString("firstname"));
doSomethingWithAge(jobj.getDouble("age").intValue());

All the proxies work in a similar way except for the Windows Phone one. Indeed, the WP proxy is asynchronous because Microsoft does not allow a sinchronous http request in the main thread. All the proxies are thread safe.

The proxies are generated on the fly by a set of specialized writers. The TDSProxyGenerator component is in charge of generate the actual proxy code in the target language/platform using one of the specialized generators.

In the next figure you can see all the available proxy generators. Some of them are there since Delphi XE but all the mobile platforms have been added in XE2.

That’s all for now.

RAD Studio XE2 will be officially presented all over the world during the “RADStudio XE2 World Tour”.

You can find the list of all launch events in the RADStudio XE2 World Tour page.

I’ll be a presenter at 3 launch events in Italy and United Arab Emitates.

These are the events where I’ll be (click to register):

RAD Studio XE2 had a lot of new features. This is really the BEST ever Delphi version since version 1.

I’ll blog about other XE2 features mostly Delphi related (as usual) so stay tuned.

Back from Brazil (all slides and code from the Brasilian Delphi Conference)

Last week I returned from Brazil where I had been to speak to the Delphi Conference.
The conference was held in St. Paul who, like many Brazilians will be able to confirm, is not a typical Brazilian city.

The warmth of local people has been exemplary. Andreano Lanusse has organized all in a really valuable way.

Besides the excellent food, I was surprised by the number of Delphi developers found: 550! In addition, over 150 people
have not had time to register and were placed on a waiting list. Fantastic.

After the inevitable David and his keynote, there were four simultaneous tracks during the day.

My talk was translated from English to Portuguese.

As imagined, the argument Android and seem to raise much interest in the Delphi community.

It was very nice to have confirmation in the first person to what is present and the large Brazilian community Delphi.

Here you can find all the slides and in my GoogleCode svn repository you can find all the DEMO code.

If you live in italy or can speak in italian language, you might be interested in the “ITDEVCON MOBILE BOOST” (http://www.itdevcon.it/).

Stay tuned.