Skip to content

Commit

Permalink
remove cluster stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
alekcz committed Jul 6, 2021
1 parent aed771c commit 18033a8
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 49 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ Going above 400 req/s generally results in bad things happening. You can test yo

## Release 0.0.2
- [ ] Perfomance improvements
- [ ] Cluster mode

## Release 0.1.0
- [ ] Store passphrases with [konserve](https://github.com/replikativ/konserve)
Expand Down
21 changes: 8 additions & 13 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,27 @@ print_help() {

default_install_dir="/usr/local/bin"
install_dir=$default_install_dir
# install_dir_opt=${1:-}
# if [ "$install_dir_opt" ]; then
# install_dir="$install_dir_opt"
# fi
install_dir_opt=${1:-}
if [ "$install_dir_opt" ]; then
install_dir="$install_dir_opt"
fi

download_dir=/tmp

latest_release="$(curl -sL https://raw.githubusercontent.com/alekcz/pcp/master/resources/PCP_RELEASED_VERSION)"
target_release="${1-$latest_release}"

case "$(uname -s)" in
Linux*) platform=linux;;
Darwin*) platform=macos;;
esac

download_url="https://github.com/alekcz/pcp/releases/download/$target_release/pcp-$target_release-$platform-amd64.zip"
download_url="https://github.com/alekcz/pcp/releases/download/$latest_release/pcp-$latest_release-$platform-amd64.zip"

cd "$download_dir"
echo -e "Downloading $download_url."
curl -o "pcp-$target_release-$platform-amd64.zip" -sL "https://github.com/alekcz/pcp/releases/download/$target_release/pcp-$target_release-$platform-amd64.zip"
unzip -qqo "pcp-$target_release-$platform-amd64.zip"
rm "pcp-$target_release-$platform-amd64.zip"
curl -o "pcp-$latest_release-$platform-amd64.zip" -sL "https://github.com/alekcz/pcp/releases/download/$latest_release/pcp-$latest_release-$platform-amd64.zip"
unzip -qqo "pcp-$latest_release-$platform-amd64.zip"
rm "pcp-$latest_release-$platform-amd64.zip"
mkdir -p "/usr/local/etc/pcp-db"
mkdir -p "$install_dir/pcp-templates"

Expand All @@ -53,10 +52,6 @@ mv -f "$download_dir/pcp-server.jar" "$PWD/pcp-server.jar"
rm -rf "$PWD/pcp-templates"
mv -f "$download_dir/pcp-templates" "$PWD"

if [ ! -e "$PWD/pcp.conf" ] ; then
echo "PCP_CLUSTER=-c" > "$PWD/pcp.conf"
fi

case "$(uname -s)" in
Linux*)
mv -f "$download_dir/pcp.service" "/etc/systemd/system/pcp.service"
Expand Down
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject pcp "0.0.2-beta.2"
(defproject pcp "0.0.2-beta.3"
:description "PCP: Clojure Processor - A Clojure replacement for PHP"
:url "https://github.com/alekcz/pcp"
:license {:name "The MIT License"
Expand Down
2 changes: 1 addition & 1 deletion resources/PCP_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.0.2-beta.2
v0.0.2-beta.3
1 change: 0 additions & 1 deletion src/pcp/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@
(let [scgi-port (Integer/parseInt (or (System/getenv "SCGI_PORT") "9000"))]
(case path
"" (scgi/serve scgi-handler scgi-port)
"-c" (scgi/serve scgi-handler scgi-port :cluster true)
(run-script path)))))


45 changes: 15 additions & 30 deletions src/pcp/scgi.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
(ns pcp.scgi
(:require [clojure.string :as str]
[clojure.core.async :as async])
(:require [clojure.string :as str])
(:import [java.nio.channels ServerSocketChannel SocketChannel Selector SelectionKey]
[java.nio ByteBuffer]
[java.net InetSocketAddress InetAddress]
Expand Down Expand Up @@ -103,38 +102,24 @@
serverChannel))

(defn run-selection [active handler ^Selector selector]
(async/thread
(while (some? @active)
(if (not= 0 (.select selector 50))
(let [keys (.selectedKeys selector)]
(doseq [^SelectionKey key keys]
(let [ops (.readyOps key)]
(cond
(= ops SelectionKey/OP_ACCEPT) (on-accept selector key)
(= ops SelectionKey/OP_READ) (on-read key handler))))
(.clear keys))
nil))))
(while (some? @active)
(if (not= 0 (.select selector 50))
(let [keys (.selectedKeys selector)]
(doseq [^SelectionKey key keys]
(let [ops (.readyOps key)]
(cond
(= ops SelectionKey/OP_ACCEPT) (on-accept selector key)
(= ops SelectionKey/OP_READ) (on-read key handler))))
(.clear keys))
nil)))

(defn serve [handler port &{:keys [cluster]}]
(defn serve [handler port]
(let [active (atom true)
^Selector selector (Selector/open)
^Selector selector2 (when cluster (Selector/open))
^Selector selector3 (when cluster (Selector/open))
^Selector selector4 (when cluster (Selector/open))
^ServerSocketChannel server (build-server port selector)
^ServerSocketChannel server2 (when cluster (build-server 9007 selector2))
^ServerSocketChannel server3 (when cluster (build-server 9014 selector3))
^ServerSocketChannel server4 (when cluster (build-server 9021 selector4))]
(run-selection active handler selector)
(when cluster
(run-selection active handler selector2)
(run-selection active handler selector3)
(run-selection active handler selector4))
(future (while (some? @active) nil))
^ServerSocketChannel server (build-server port selector)]
(future
(run-selection active handler selector))
(fn []
(.close server)
(when cluster (.close server2))
(when cluster (.close server3))
(when cluster (.close server4))
(reset! active false))))

2 changes: 1 addition & 1 deletion src/pcp/utility.clj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

(def root (atom nil))
(def scgi (atom "9000"))
(def version "v0.0.2-beta.2")
(def version "v0.0.2-beta.3")

(defn keydb []
(or (env :pcp-keydb) "/usr/local/etc/pcp-db"))
Expand Down
2 changes: 1 addition & 1 deletion test/pcp/utility_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
_ (io/make-parents (str "./test-resources/pcp-db/" project ".db"))
_ (new-folder root)
_ (utility/stop-scgi)
scgi (core/-main "-c")
scgi (core/-main)
local (utility/-main "-s" root)
_ (Thread/sleep 2000)
file-eval (json/decode (with-out-str (utility/-main "-e" (str root "/index.clj"))) true)
Expand Down

0 comments on commit 18033a8

Please sign in to comment.