Friday, April 8, 2016
I had intended to insert 100K entries to a dictionary in memory. I was reading those files from file in Unity as seen below.
However it took about 11 seconds to insert 100K entries into memory. First I was suspected with the special ternary tree I was using to store strings. After examining the problem; I found that problem was related with a mono bug. If your text file has UNIX endings (/n) problem occurs. If you replace all end lines with microsoft style (/r/n) problem disappears. Time decreased from 11 seconds to 0.2 seconds!
Meanwhile; in order to do changing line ending (and applying some other business related filters) I used Kotlin language for the first time and I was very happy to see such a simple and efficient language.
Monday, May 25, 2015
The tricky part here is; when non ui thread completes it's job; it should trigger the "callback method" called by Ui thread instead of calling it self directly. (Otherwise Unity would complain that you were trying to access unity libs from a non ui thread and you would also break single thread mechanism.)
In the following code you can see that, DoJobAsync is called from Ui thread; and we pass a JobResultHandler which should be called from Ui thread when the non-ui thread finishes it's job.
In gistfile1.cs#6 you see that we only create a ThreadAdapter if there is a callback parameter to prevent object creation cost. Of course this can be improved by object pooling etc. ThreadAdapter ia created in Ui thread since it is an Unity game object.
After ThreadAdapter is created; in every frame/in x seconds (it's your decision); it checks a volatile variable named waitCall. waitCall is set to false from non-ui thread when it completes it's job in gistfile1.cs#25.
I think the code is more clear :). Please see it below:
Tuesday, December 3, 2013
Tuesday, October 8, 2013
Today I exposed a web service as a restful HTTP service via Datapower. I am also one of the consumers of this restful service and I push this data to clients who are subscribed to me.
However I noticed that the data I receive does not frequently change and I do not want to push same data.
So I added a http response header in Datapower which is actually a checksum of the content I requested; in my code I check this checksum if it is different from the one I got in my previous request:
Monday, September 23, 2013
If you are using Servlet 3.0 API to do some async stuff, do not forget to switch to NIO Connector by setting protocol attribute of the connector element in server.xml and using an executor. There are two important reasons for this: Thread pooling and timeout behavior of AsyncListener.
There are 10 threads in my ExecutorService to handle requests in my AsyncContext pool. Here is a sample; let's assume that we push awesome data to clients in a comet fashion such:
If you leave Tomcat 7's default configuration; you will have n+10 threads. "n" is the number of requests. This is due to nature of blocking connectors. This might be useful for some applications (where for example thread local variables are highly used etc.). However; due to nature of the asynchronous job we are doing (we are pushing data to client when an event occurs) what we like to achieve is to satisfy all the clients with less threads; since most of the time threads are doing nothing but waiting.
Change your connector to NIO and use a thread pool for the NIO connector as seen from a server.xml fragment below:/p>
Connect with jprofiler; send 500 threads with jmeter; you will see only ten threads at the front; delivering those requests to 10 worker threads we defined above. To make it really look like a node.js; set maxThreads="1" minSpareThreads="1" of executor element. There were no changes in performance in my case due to fact that I wait for a second in my loop which schedules pushes to clients; so each client is pushed once a second approximately. In real life; an event will cause this push.
I really like this architecture rather then node.js due to fact that I know exactly the thread counts and I can manage them all. And please post me why node.js is better? I just can not understand. You have more libraries in java, you can integrate with many other systems easily; you can write in java,ruby,js,groovy,scala etc..
If your are setting timeout on AsyncContext such:
And then add an AsyncListener to that AsyncContext; OnTimeout of AsyncListener is called depending on which connector of Tomcat you are using.
If you are using Http11Protocol (BIO): callback is called exactly the time passed from the first request. If you give a high timeout and user closes his browser; still timeout is not called and you have to push data since you are not aware of it.
If you are using org.apache.coyote.http11.Http11NioProtocol (NIO); callback is called exactly the time you set after the connection is closed (for example if the browser is closed).
Thursday, September 12, 2013
Although NTLM is insecure and being deprecated; I was required to transform basic http authentication to NTLM.
Use the above message sender as displayed below in your ws outbound gateway.
Thursday, September 5, 2013
I would like to share a simple configuration I have done in order to extract an URL from given XML, fetching it and encoding the content while returning it in soap response. It might be valuable for those who are looking for selecting xml elements in xsl regardless their namespace and how to transform binary content.
First we should extract ip, port, path and query arguments and construct a full URL. No need to say that this is the worst representation for an URL; but this is what asked from us.A sample xml is: The URL extractor XSD is (AtmesUrlExtractor.xsl in policy flow):
After extracting the URL and assigning the result to a variable atmes_fetch_url; we use fetcher component to fetch the content (in this point we reference to variable with var://context/atmes_fetch_url):
This fetcher puts content is into "PIPE". Then our binary transformer is activated:
The important thing above is call to pkcs7-convert-input.ffd. It puts all the content in a xml structure so that we can proceed with xslt although it is not an xml actually. It is very easy to understand how it works; it is a standard file in datapower. It puts all the content under object/message tag. The import thing is that you must choose it as a binary in component details screen as seen below (even if it is not a binary; a text; anything which is not xml.)