in my web based app, i decided to use Cherrypy 3.2 as http framework.
I am using the cherrypy.Application class to create WSGI compatible appliaction object, which is served via Apache2 with mod_wsgi.
Also, I am using just core components of SQLalchemy 0.7.3 (not ORM). There are available some tools for cherrypy for correct session binding per request (like SATools). But Session object of SQLalchemy is part of the ORM, not the core.
So I have started thinking about how to make similar tool but without session.
The documentation of SQLalchemy says:
For a multiple-process application that uses the os.fork system call,
or for example the Python multiprocessing module, it’s usually
required that a separate Engine be used for each child process.
So how to correctly create one engine per cherrypy thread? Taking note that the threads are created by apache2 (probably).
Thank you!!
edit: it is maybe important, that wsgi application is ran in daemon mode by apache2
Under mod_wsgi I don't think this is an issue if I understand the question because the application isn't preloaded into memory prior to the fork in mod_wsgi. Instead, the application is separately loaded into each distinct process so there are no issues from shared stuff due to inheritance across a fork.
Related
By which mechanism is apache module loaded during runtine, or during startup ?Are in that process used mechanisms like interprocess communication ? Is apache actively calling methods in module, or module itself calls apache method, or both.
For example, get request commes to apache and mod_spnego (kerberos authentication) is loaded. How does apache know when to call main function in module code ?
Apache and its modules are written in C. The modules are loaded during the startup, from shared object files (.so on Unix, .dll on Windows or as Dynamic Shared Objects). When building the Apache HTTPD, it's also possible to compile the modules statically into the httpd binary. Both way, they work from the same process.
How does Apache know when to call main function in module code?
Take a look at these articles, and see what's said about Hooks.
Apache 2.2, Converting Modules from Apache 1.3 to Apache 2.0
The new architecture uses a series of hooks to provide for calling
your functions. These you'll need to add to your module by way of a
new function, static void register_hooks(void). The function is really
reasonably straightforward once you understand what needs to be done.
Each function that needs calling at some stage in the processing of a
request needs to be registered, handlers do not.
Developing modules for the Apache HTTP Server 2.4
When handling requests in Apache HTTP Server 2.4, the first thing you
will need to do is create a hook into the request handling process. A
hook is essentially a message telling the server that you are willing
to either serve or at least take a glance at certain requests given by
clients. All handlers, whether it's mod_rewrite, mod_authn_*,
mod_proxy and so on, are hooked into specific parts of the request
process. As you are probably aware, modules serve different purposes;
Some are authentication/authorization handlers, others are file or
script handlers while some third modules rewrite URIs or proxies
content.
I have a simple database application in mind and I am thinking of making it browser-accessible instead of creating a standalone one.
I almost finished creating the DB schema in a PostgreSQL Server and I will now start developing. My first idea was using PHP or Ruby On Rails to manage the backend logic and interfacing with the DB, but since this application is fairly simple I think that I can easily implement all business and data manipulation logic with JavaScript or with the DB triggers.
So I am now wondering: is there a way to directly send the queries to a PostgreSQL Server, without server-side scripting?
More generally: can a PostgreSQL(9.3) Server receive the queries in Http requests and provide the results in Http responses?
I know this might sound stupid, and I am not looking for answers like "Use JS for presentation, PHP for logic and DB for data storage". I believe this is a lightweight solution for a very simple application, so I want to try it if possible!
Yes, That is possible.
What you can do is to send it via REST API. (post, get request ).
Here are some reference for you:
https://github.com/begriffs/postgrest
https://github.com/pgrest/pgrest
Please take a look at this for more HTTP API
[update!]
This idea is currently not possible (as I tought when I answered you before).
I tought it was possible after checking this node-postgres library written in javascript but it uses Node.js specific functions not present in the web browser as stated by the library's creator himself and this answer at stack overflow.
There is this package called browserify that exports a Node.js javascript file into a browser front-end ready javascript file. The problem with node-postgres + browserify is that it throw some errors during the browserification process, precisely when it tries to access libpq (an API written in C for accessing PostgreSQL).
I'm sorry I have mistaken you
Yet I still have a suggestion for you. You can try CouchDB if you really want to build a backendless/serverless application. It is natively RESTful, handles authentication and authorization at some extent, is opensource but unfortunately: NoSQL. It processes queries based on Map/Reduce paradigm and Mango query language so it's an entire different world for you to discover if you are used with SQL.
[old answer, I'm leaving it here for learning purposes]
Have you considered using a PostgreSQL driver for JavaScript? It is not RESTful, but it can connect to PostgreSQL and query it!
The library is called node-postgres and you can download it via npm
https://www.npmjs.com/package/pg
Just don't forget to enable SSL connection in the PostgreSQL server and in the client to avoid man-in-the-middle attacks.
An here's a tip: if you need an ACL for allowing or denying selects or inserts for specific users you can manage that through PostgreSQL user management and privileges. PostgreSQL has row level security, allowing you to define which rows in a table can be selected updated and deleted for a given set of users or groups.
I come from a PHP and .NET world where I understand the environment fairly well. However I can't find a newbie explanation of how the Ruby / Ruby on Rails stack actually work with these web server.
Are they more close to the PHP model, where all classes of an application are loader for each request and there is no default shared memory, or is it like an application server where an active app sits in the memory and handles requests?
How is it with reloading when a file changes? Does the app in an application server has to be restarted? How does it know? Does it monitor file system?
I have seen that both the Ruby Version Manager (rvm) and the newer rbenv from 37signals shomewhat shuffles with the ruby command on OS X / Linux. This seems like a total magic to me. Does a webserver just runs ruby command and does not care where the interpreter is resolved in the $PATH?
Webrick is the default server of Rails and is usually used for developing and testing.
Rails is session based like PHP is. If you want to run in production you will generally use Phusion Passenger on Apache or Nginx, dont worry about that for now.
If you run in Development or Test environment you can edit your application files(views, controllers and models) and they will be reloaded on each request (even if they are not edited).
Have a look at generating a project and scafolds with Rails to get you started.
http://guides.rubyonrails.org/getting_started.html
We are having issues with IIS6 slowdowns when using more than 1.2GB of RAM in a single worker and would like to use more workers. However looks like ASP sessions are made by worker and when the browser accesses some page through another worker it losts the ASP session.
Do you have some tips on how to solve this problem?
We are considering to use some other way to manage session separately from IIS (not database, maybe memcache?). Do you recomend something?
Note.: The application is full of legacy code and we need to avoid big changes in code.
I've had a similar scenario with a legacy app in the past and ended up writing a simple component to serialize the ASP Session object to & from the database.
I have written a central session store for classic ASP in the past using Redis as a storage layer. The code is freely downloadable at https://gitlab.com/erik4/classic-asp-book-examples
It uses a redis ActiveX/COM component, available here.
Using a central session store using Redis will allow you to use as many worker processes as needed.
If you want a detailed explanation of the implemantation, there's an accompanying book, but the example code should work out of the box.
Is Ruby a client- or server-side language?
Both?
After all, there are Ruby programs which are not used as part of a client-server architecture.
If you are talking about Ruby on Rails, then it's typically only used on the server side.
Ruby is an all-purpose script/programming language which can be executed on both client and server environments.
As client-side, you can use it to create a GUI application (or CLI one) to interact with data, communicate with a server, play with media/game, etc. Some framework examples on this level would beShoes, MacRuby, etc.
As server-side, you can use it to store and save data, validate and execute transactions, etc. It's where frameworks like Rails, Merb, Sinatra and others take place, and its -arguably- it's most known mode of operation.
As the previous poster said, on the context of a server/client web application arquitecture, Ruby would be run on the server side. If I'm not mistaken, there have been some advances for running Ruby through the browser (like JS does), but probably not something to be considered for production ready needs.
Ruby does not (typically) execute in the browser, so if you are asking this in the context of a web server/client browser, then Ruby is server-side.
You can of course also execute stand-alone Ruby code on any machine with a Ruby interpreter. It is not confined to web applications.