úterý 18. února 2014

Introducing Infinispan OData server: Remote JSON documents querying

Dear Infinispan community,
We are proud to announce the very first available version of Infinispan OData server.

This brand new standalone HTTP server is based on odata4j framework (its core is running on OData Jersey) and using Infinispan as an underlying JSON document store.

Clients are allowed to use OData standard query language and OData service operations for communication with the server, storing and obtaining requested JSON documents.

Infinispan OData server understands an internal structure of JSON document, and therefore, clients can query the cache and ask for a collection of results in dependence on specified expression operators.



What's Open Data Protocol (OData)?

 

OData frees stored information from current data silos and exposes the data for variety of possible consumers. To achieve that, OData utilizes common web technologies: HTTP, REST, JSON and Atom Publishing Protocol.

From clients' point of view, databases offer usually diverse APIs. OData focuses its effort on a creation of an uniform access pattern for various sources of data, to unlock them and prepare for broad consummation.


The picture is used from OData introduction video on http://www.odata.org/.

Any HTTP client can access the data or there is also plenty of consumers present in OData ecosystem. And we just added another producer into that ecosystem -- Infinispan OData server which exposes JSON documents stored in caches to various number of clients using industrial standard and platform independent way.

More information about OData: http://www.odata.org/


Our challenge: 

 

Generally, NoSQL solutions lack overall portability as they are different one from each other and almost each database of this kind provide an unique interface for accessing stored data.

Infinispan is not an exception and its library mode usage is mainly focused on Java clients. However, Infinispan did a step further to solve this problem by introducing its server modules. A few implementations of an Infinispan Hot Rod client were developed to support a few different programming languages. There is also an Infinispan REST server which provides an HTTP access to key-value store capabilities. The problem is that users are not able to effectively use Infinispan for operating with documents in commonly adopted JSON format.



Sure thing that Infinispan REST server allows users to store data in JSON format. The only problem is that our REST server supports only key-value access approach as it does not understand internal structure of JSON documents. Therefore, when you have for example cars in your cache, you can access them through their unique keys only. One key -- one value, classic.
But in some cases it could be beneficial to be able to access your data using specific filters and possibly obtain even a collection of results meeting specified criteria.


This is the main advantage which Infinispan OData server offers. As you can see in the picture, OData server understands internal structure of JSON documents and (let's talk in pseudo language for a while) you can obtain "all red cars" without any problems.

And that's it!


Interface

 

You might be interested how you can interact with the server. Recently, it is enough to use any HTTP client, REST methodology and follow OData service operations exposed in server metadata document which describes server interface capabilities and is accessible at:

http://localhost:8887/ODataInfinispanEndpoint.svc/$metadata

Putting data into the cache:


HTTP POST request at:
http://localhost:8887/ODataInfinispanEndpoint.svc/odataCache_put?key='person1' 

with JSON document in the body will do the trick. For obtaining the data, you have two options:

Key-value approach:


HTTP GET request at:
http://localhost:8887/ODataInfinispanEndpoint.svc/odataCache_get?key='person1'

Query approach:


HTTP GET request at:
http://localhost:8887/ODataInfinispanEndpoint.svc/odataCache_get?$filter=
name eq 'Morpheus' and lastname eq 'Matrix'

Full interface is introduced in project README file.


Solution

 

We were able to achieve desired functionality using the @FieldBridge from Hibernate search which helps us to add fields from JSON objects into the Apache Lucene Document and get it indexed. All with help of odata4j framework (http://odata4j.org/).

For now, code is located at: https://github.com/tsykora/infinispan-odata-server/ -- please follow README where you can find information about building, dependencies, server interface and practical usage examples.

Infinispan OData server is the main deliverable of the tsykora's diploma thesis -- for further details accessible at: https://is.muni.cz/auth/th/325144/fi_m/ diploma_thesis.pdf file with the text part and tsykora_attachment.zip archive which contains essential libraries and already built server itself (version 1.0). We also benchmarked this new server against already existing Infinispan servers (Hot Rod, Memcached, and mainly REST in 4-node clustered environment) using Infinispan cakery tool which is based on PerfCake framework.

We managed to significantly improve performance of odata4j framework libraries for our needs but there is still much to investigate there. Infinispan OData server project is very young (started in June 2013) and was developed under respective time constraints.

As we have mentioned, this small Infinispan sub-project is in the early stage and we are gathering feedback and feature requests. Feel free to open new issue in GitHub project repository. Now we plan to focus on more performance improvements, code polishing and addition of more cool features, support for more OData operators and embedded JSON documents, lists, number fields etc. 

Stay tuned!

neděle 26. ledna 2014

Happy blogging with do-it-now-and-don't-be-perfect method

Hi all! :)
You are reading this stuff probably because one of my posts was pointing right here. I promise I will keep an introduction of do-it-now-and-don't-be-perfect method very short.

    The method incorporates 2 approaches. Do it now -- when you have an idea just open a Blogger and jot it down very quickly, and immediately. Of course I wanted to do this every time. So why didn't I do it? Because I was striving for a perfection in my former blog posts.

    Perfect grammar (as I'm not a native English speaker), perfect citations, perfect ideas, perfect agenda of the post, perfect structure, perfect conclusion, perfect, perfect, perfect everything.

    My brain started to think about what else do I need to make a perfect post instead of writing it right now. What I need to add, do, solve? I need to re-read it 3-4 times once the post is written to be sure there are no unnecessary mistakes there. I need someone to read it before publishing to make sure there are no completely wrong ideas stated in the post... etc., etc.

    I wanted to have it PERFECT.

    And all those tasks take simply too much time and it's too much effort to deal with them. 

    It works literally like a KILLER of my fresh ideas, fresh experience, or fresh mind stream which MIGHT be worth to share. With a perfectionism I had even no chance to find out whether it was worth or not because I didn't publish almost anything. 

    Now I declare: "FU*K you PERFECTIONISM" -- you will no longer stop my willingness to share any of my ideas.  


úterý 21. ledna 2014

Adjust your sleep: two years of polyphasic experience

Hi all! :)
Today's agenda: to share some of my experience with polyphasic sleep (http://en.wikipedia.org/wiki/Polyphasic_sleep).
     Why? Simply because I can... and I can because of 2 main reasons. 1) I did it. It's finally working for me exactly as I wanted to in its very beginning. 2) I have found a time for posting it, together with a lot of enthusiasm using DO-IT-NOW-AND-DON'T-BE-PERFECT method.

     You've probably heard about strange people who divide their sleep into more segments. Just look at ^ wiki page to find out more about particular patterns. If I understand it correctly (a lot of material, sources, blog posts) the main idea or the principal reason why people do this -- is to spare some time. For example "Everyman pattern with 2 naps" where one spends 4,5 hours in core and 2x20 minutes in 2 power naps. 4:30 + 0:40 = 5:10, 5 hours and 10 minutes of sleep which basically adds 3 extra hours when comparing to someone who slept full 8 hours. That's it. Once you adapt to it and learn to work with those patterns, you should be able to by productive at the same rate (even more) as someone who sleeps 8 hours, and additionally, you should have some extra time for yourself, your work, your family, hobbies... for writing posts like this.

     For writing post like this... really? Actually, this is not my case right now and I will tell you why. After some diploma-thesis burst and caffeine experiments where I totally ruined my regular sleep cycles, here it comes a period of a time when I need to "just and only" study for my final examination. First thing what I did was to completely get rid of a caffeine and focus on jumping back into my polyphasic sleep train.

     In my case, I don't care about a sparing of a time now but rather focus on sleep pattern effectiveness with regards to studying and learning.

     How do I sleep now? The first 4,5 hours core, 2-3 hours of work (studying things, this blog post, anything), the second core (varying) 1,5h to 3h following my body needs and one power nap during the day. So I can basically end up with 4,5+3 = 7:30 + 0:20... approx 7 h 50 min of a sleep per day, let's say 8. So I sleep 8 hours in total which is the same amount as a decent one-phaser.

     So why am I doing this? It's beneficial even only for those 2-3 hours of work phase between 2 core sleeps. This is my super-power-hyper-mega effective working time. This 2to3-very-productive-hours-chunk is usually placed somewhere between 4 and 9 AM, depending on the exact time when I have felt asleep. 

     Today's observation: It helps me to be hungry. Basically "the hunger" feeling is able to wake me naturally after 4,5 hours of a sleep. For me, hungry in the early morning hours means one yoghurt or cottage just before sleep. Sooooo NO a half of a fried duck with dumplings and red cabbage at 10 PM!! (I did that two days ago and it was awesome anyway.)

     Of course, I have slightly opened window jalousie to allow the sun/day light come inside and wake me up naturally. There exists even some special alarm clocks in the market... those are able to simulate sunrise via lightening up a lamp gradually and even add some bird singing. Awesome! :))) Hmmm, formerly, I meant this one as a joke, but such an alarm clock can be very beneficial in a case when a street light is distracting you from core sleep, when you need the most darkest place as possible and you simply need to completely close your jalousie and you need to simulate natural daylight using some technological solution. Ok.

     Next, caffeine-free way -- I just stopped using caffeine. By stopped I mean stopped after one month experience when I was fully working on my diploma thesis and caffeine helped me to broke my sleep pattern in order to be able to program more code, write more technical text, stay focused during late hours, improve my coding performance together with epic music, etc. (Experience during this phase deserve standalone blog post as well -- later)

     I don't want to have literally NONE of above-mentioned things right now. I need to study, my brain has to be in "sleepy" phase to be able to absorb, process and store a bunch of information. Division into 3 phases will help to stay in REM-like phase which, I am strongly convinced about it, is beneficial for learning. (<< source needed here -- later)

    So, now I've spent some around 1 hour writing this post, eating a breakfast, thinking and I will probably be able to study for a next oncoming hour period. After that I will sleep again for next 1,5 or 3 hours. Yeah, every time you need to make sure that you sleep in 1,5 h intervals as REM phases are ending there. I.e. 1,5 h, 3 h, 4,5 h, 6 h, 7,5 h. If you go sleep at 1 AM and have to get up at 6 AM, set your alarm clock at 1+4,5 = 5:30 AM rather than 6 AM. At 6 AM you will probably meet your deep sleep phase and your day will sucks. I am pretty sure you know that feeling ;)

     That's it. Just wanted to share some thoughts, finally. Anyway, that was very nice procrastination as I didn't need to study and my brain is internally satisfied by writing a blog post :D
__________________________
I wrote this post using DO-IT-NOW-AND-DON'T-BE-PERFECT method (I will probably elaborate in next post) which was developed internally by my creative mind to control my perfectionism (fu*k you!) and finally made me able to share my thoughts with others more effectively. Which means that you can find more grammar mistakes, not entirely the best citation norms, you can find just a raw record of my mind stream -- probably nothing for your diploma thesis to base on :D

pátek 19. dubna 2013

Internal microphone ThinkPad T520 does not work with Fedora 16

Hi, 
This is my personal, very short and simple guide how I have set my internal microphone working on ThinkPad T520 and Fedora 3.3.0-4.fc16.x86_64.   

Switch to root and open config file /var/lib/alsa/asound.state See differences in control points 6 to 12 below. 
Generally – values have to be set as true or higher than 0 etc. After editing and saving run this command: sudo alsactl restore (and check if it works)  

Note! My Fedora implicitly deletes this changes after boot. It can be useful copy that fixed version of asound.state and simply rewrite it and restore again. 
More sophisticated method – set up cron job for this. 
  

Note2! Some people experienced problems with restoring modified asound.state file. In that case simply create new file with correct settings and load it using --file in alsactl because it points on /var/lib/alsa/asound.state file by default.

My control.6 to control.12 changes in asound.state file:


control.6 {
        iface MIXER
        name 'Mic Boost Volume'
        value.0 4
        value.1 4
        comment {
            access 'read write'
            type INTEGER
            count 2
            range '0 - 4'
            dbmin 0
            dbmax 4000
            dbvalue.0 4000
            dbvalue.1 4000
        }
    }
    control.7 {
        iface MIXER
        name 'Mic Capture Volume'
        value.0 80
        value.1 80
        comment {
            access 'read write'
            type INTEGER
            count 2
            range '0 - 80'
            dbmin -7400
            dbmax 600
            dbvalue.0 600
            dbvalue.1 600
        }
    }
    control.8 {
        iface MIXER
        name 'Mic Capture Switch'
        value.0 true
        value.1 true
        comment {
            access 'read write'
            type BOOLEAN
            count 2
        }
    }
    control.9 {
        iface MIXER
        name 'Internal Mic Boost Volume'
        value.0 2
        value.1 2
        comment {
            access 'read write'
            type INTEGER
            count 2
            range '0 - 4'
            dbmin 0
            dbmax 4800
            dbvalue.0 4800
            dbvalue.1 4800
        }
    }
    control.10 {
        iface MIXER
        name 'Internal Mic Capture Volume'
        value.0 80
        value.1 80
        comment {
            access 'read write'
            type INTEGER
            count 2
            range '0 - 80'
            dbmin -7400
            dbmax 600
            dbvalue.0 600
            dbvalue.1 600
        }
    }
    control.11 {
        iface MIXER
        name 'Internal Mic Capture Switch'
        value.0 true
        value.1 true
        comment {
            access 'read write'
            type BOOLEAN
            count 2
        }
    }
    control.12 {
        iface MIXER
        name 'Master Playback Volume'
        value 74
        comment {
            access 'read write'
            type INTEGER
            count 1
            range '0 - 74'
            dbmin -7400
            dbmax 0
            dbvalue.0 0
        }
    }