I have a isapi filer and I want to add a logic based on the incoming domain ( my server farm hosts many domains).
There domain list is dynamic , I can export these domain list into a text file and read it from the isapi , but is there a way to keep this file in memory (is array or linked list) to save the IO call.
similar to global application state .
How are your worker processes distributed across your servers? Do you have one server with one worker process, or multiple servers?
If you have one server with one worker process, you can just read the file into a static array or string to manage it (just make sure you account for concurrent threads reading/modifying it simultaneously)
If you have multiple worker processes on just one server, you can use named shared memory. I've used this before in ISAPI filters to share information, and it works pretty well. It should even take care of concurrency for you. You can read more here: http://msdn.microsoft.com/en-us/library/aa366551%28v=vs.85%29.aspx
If you're spread across multiple servers, you could use a distributed cache like memcached. This is more complex to set up, but it'll give you good performance. There's a thread on setting this up here: C++ api for memcache
Related
I want to make webserver with ocaml. It will have REST interface and will have no dependencies (just searching in constant data loaded to RAM on process startup) and serve read only queries (which can be served from any node - result will be the same).
I love OCaml, however, I have one problem that it can only process using on thread at a time.
I think of scaling just by having nginx in front of it and load balance to multiple process instances running on different ports on the same server.
I don't think I'm the only one running into this issue, what would be the best tool to keep running few ocaml processes at a time and to ensure that if any of them crash they would be restarted and have different ports from each other (to load balance between them)?
I was thinking about standard linux service but I don't want to create like 4 hardcoded records and call service start webserver1 on each of them.
Is there a strong requirement for multiple operating system processes? Otherwise, it seems like you could just use something like cohttp with either lwt or async to handle concurrent requests in the same OS process, using multiple threads (and an event-loop).
As you mentioned REST, you might be interested in ocaml-webmachine which is based on cohttp and comes with well-commented examples.
I am doing simple web programming using c++ in Apache, Linux. I created a cgi script called signup.cgi. This program gets input from browser and write the data in a file called users.txt.
My question is, when two user access the signup.cgi, will it be create two different processes or only one process?
Case 1: Will it be two different Processes to access users.txt?
User1 ----> singup.cgi -----> Pid1 ----> users.txt
User1 ----> singup.cgi -----> Pid2 ----> users.txt
(or)
Case 2: Will it be only one process to access users.txt?
User1 ----> singup.cgi -----> Pid1 ----> users.txt
User1 ----> singup.cgi -----> Pid1 ----> users.txt
If It is two different processes access users.txt in same time, data in users.txt will be corrupt. How can I handle this Issue?
If It is only one process to access users.txt, I don't know what are the problems that I may get?
Apache's use of processes depends on how your server and your CGI "script" are configured. According to RFC 3875:
The CGI "script" that is invoked by the server can be a standalone program, a
dynamically-loaded or shared library, a subroutine in the (Apache software) server, or an interpreted script (See section 1.4)
"The most common implementation of CGI invokes the script as a child
process using the same user and group as the server process." (See section 9.5). But the FastCGI variant, which manages a pool of processes, to avoid the overhead of launching new processes for each request.
The script should be stateless. See section 9.7:
The stateless nature of the Web makes each script execution and resource retrieval independent of all
others even when multiple requests constitute a single conceptual
Web transaction. Because of this, a script should not make any
assumptions about the context of the user-agent submitting a
request.
To reinforce this fundamental recommendation, think that in scalable operations you may have a load balancer that routes incoming http request to one of many apache server, and the apache server could route the requests to one or of several FastCGI services. If you think stateless, you'll be safe !
So in conclusion: in your CGI program you can't assume nothing about processes and users (you have to manage sessions if you have to put related requests together).
And yes, if several processes write to the same file in the same moment, you could get real garbage in your file. You'll have to use OS level interprocess synchronisation mechanisms to manage that. Semaphores or file locks could sequentialize file access but decrease performance. memory mapped files could help in an easier fashion.
But to overcome this limitation, you'll have to achieve an architectural quantum leap. The topic is far too broead to be developped here, but for example:
use of a message queue: each process sends data to a message queue (in another process) that will handle it as soon as it can, but without delaying the request processing.
use a service oriented architecture, where each process routes request to a service, such as for example a database or object persistence layer.
I trigger an event from a custom tool and I have 4 linux servers where I need to monitor logs and grep for a particular event ID.
The event ID could occur in any ONE of the 4 servers.
I wrote a method that will make a ssh session checks for the grep pattern. Since there could be many servers added, I used a threading module to look concurrently in all the servers a specified time.
If the match is found in one server, I want other threads to die. Is there a way I can inform to other threads to stop searching if the pattern is found in one? Is it safe?
I have many of these kind of functionality to be verified in many servers. So, I do not want to waste any time doing it in serially and want to save memory by stopping other threads.
SAS has a stored process server that runs stored processes and a workspace server that runs SAS code. But a stored process is nothing but a combination of SAS code statements, so why can't the workspace server run SAS code?
I am trying to understand why SAS developers came up with the concept of a separate server just for stored processes.
A stored process server reuses the SAS process between runs. It is a stateless server meant to run small pre-written programs and return results. The server maintains a pool of processes and allocates requests to that pool. This minimizes the time to run a job as there is no startup/shut down of the process overhead.
A workspace server is a SAS process that is started for 1 user. Every user connection gets a new SAS process on the server. This server is meant to run more interactive processes where a user runs something, looks at output and then runs something else. Code does not have to be prewritten and stored on the server. In that scenario, startup time is not a limiting factor.
Also, a workspace server can provide additional access to the server. A programmer can use this server to access SAS data sets (via ADO in .NET or JDBC in Java) as well as files on the server.
So there are 2 use cases and these servers address them.
From a developers perspective, the two biggest differences are:
Identity. The stored process server runs under the system account (&sysuserid) configured in the SAS General Servers group, sassrv by default. This will affect permissions (eg database access) at the OS level. Workspace sessions are always run under the client account (logged in user) credentials.
Sessions. The option to retain 'state' by leaving your session alive for a set time period (and accessing the same session again using a session id) is available on for the Stored Process server, however - avoid this pattern at all costs! The reason being, that this session will tie up one of your multibridge ports and play havoc with the load balancing. It's also a poor design choice.
Both stored process and workspace servers can be configured to provide pooled sessions (generic sessions kept alive to be re-used, avoiding startup cost for frequent requests).
To further address your points - a Stored Process is a metadata object which points to (or can also contain) raw sas code. A stored process can run on either type (stored process or workspace) of server. The choice of which will depend on your functional needs above, plus performance considerations as per your pooling and load balancing configuration.
Ok, strange setup, strange question. We've got a Client and an Admin web application for our SaaS app, running on asp.net-2.0/iis-6. The Admin application can change options displayed on the Client application. When those options are saved in the Admin we call a Webservice on the Client, from the Admin, to flush our cache of the options for that specific account.
Recently we started giving our Client application >1 Worker Processes, thus causing the cache of options to only be cleared on 1 of the currently running Worker Processes.
So, I obviously have other avenues of fixing this problem (however input is appreciated), but my question is: is there any way to target/iterate through each Worker Processes via a web request?
I'm making some assumptions here for this answer....
I'm assuming the client app is using one of the .NET caching classes to store your application's options?
When you say 'flush' do you mean flush them back to a configuration file or db table?
Because the cache objects and data won't be shared between processes you need a mechanism to signal to the code running on the other worker process that it needs to re-read it's options into its cache or force the process to restart (which is not exactly convenient and most likely undesirable).
If you don't have access to the client source to modify to either watch the options config file or DB table (say using a SqlCacheDependency) I think you're kinda stuck with this behaviour.
I have full access to admin and client, by cache, I mean .net's Cache object. By flush I mean removing the item from the Cache object.
I'm aware that both worker processes don't share the cache data. That's sort of my conundrum)
The system is the way it is to remove the need to hit sql every new-session that comes in. So I'm trying to find a solution that can just tell each worker process that the cache needs to be cleared w/o getting sql involved.