I've been playing with Nim on and off for a few days, today is the first day I've really done anything proper with it.
And I'm impressed.
A little background, I'm a web developer and I speak a handful of programming languages, including CFML, Python, AutoIt, LiveCode, JavaScript, but I've done very little lower level coding.
I wanted to create something real, I've no interest in making a ToDo application, or four thousand hello world variants.
So I set out to make a Markdown based server.
At first I looked at Jester, but I personally did not like some of the solutions, like static folders, so I rolled my own.
I went looking for Markdown libs, but didn't find anything that was separate enough or complete enough to be useful to me, so I rolled my own.
And be damned, after about a half-day of tinkering with this, I have a webserver that handles processing partial Markdown, does caching (With automatic re-processing after changes to the source file), and is blazingly fast.
I know I'm asking a lot of stupid questions on the forum, but it's all for a purpose, and I'm not just playing around.
I don't have enough to show yet, but I've been wanting to create something like this for a while, and now I'm finally doing it, once I have a decent amount of the commonmark.org Markdown spec implemented, I'll be releasing it free and open source (MIT or GPL 3).
So thank you, to everyone who's putting up with my stupid questions, and hopefully I'll be able to give back to the community soon enough :)
Nim is very impressive, fast, and not that hard to learn the basics of.
Nice to hear that you are impressed with Nim!
At first I looked at Jester, but I personally did not like some of the solutions, like static folders, so I rolled my own.
Why did you not like this? How did you do it in your version?
I'll be releasing it free and open source (MIT or GPL 3).
MIT please! Add it to the Nimble package repository when it's ready!
I dislike the idea of static folders, because it limits you to a single project, I just don't see the upside to "assumed" paths or folders.
My solution was to just check if the file that's being requested exists, and if it does then serve it up, no matter what kind of file it is.
I'm adding secure folders (Server can read resources out of it, but clients can not request files in them), limiting access to the server root (To avoid serving up files other than the intended web files)
Now, Jester does things mine doesn't, for example I only handle 200 and 404 status right now, but will be adding more as I go.
Not to mention I'm having lots of fun figuring out how to put together this server, instead of relying on someone elses server and just adding the dynamic processing.
I have to read up on license differences, I can't remember the difference between MIT and GPL 3 off the top of my head.
Impressive first project! I am trying to learn Nim as well; looking forward to checking out the code for your project.
Seconding the MIT license especially if this project is mainly a learning exercise.
Yeah I'm looking at using the MIT license, the code is not pretty, step one is just making it all work like I want it, then on to optimizations, but regardless of license, it'll be available free and open source, it's a learning exercise but I like to set my goals high.
Right now it handles a subset of Markdown, serves webpages, and has simple content caching (It is blazingly fast)
I found two, one that said it was far from being complete, and another that was wrapped up in other stuff rather than being available for simple markdown in, html out.
But that's ok, it's a learning experience, and I'm about to see if I can template this stuff rather than regex replace.
Maybe you can release your framework so it can be benchmarked. The current ones don't seem to do very well, being behind Python and Ruby solutions.
https://www.techempower.com/benchmarks/#section=data-r9&hw=i7&test=json
I'd love to get some hard data on performance, I've no delusions about beating the established ones, but I do think I can outdo a number of other implementations.
I'll see about making a more barebones version that only serves up static pages (Regular web pages and files) and see about testing it.
I'm looking at the requirements on the test page, and at a glance nothing stands out as being that bad, but we'll see :)
Going with their recommendation of starting with tests 1,2,3,6, which are all basic web stuff.
The current ones don't seem to do very well, being behind Python and Ruby solutions.
I have done some work speeding up HTTP servers in Nim, you can see the results here: https://github.com/def-/nim-http-speedup
I just have to clean up my branch and make a PR to Nim (and figure out how to properly parallelize maybe): https://github.com/def-/Nim/commits/parallel-httpserver
The summary is that with a single thread Nim's asynchttpserver can now beat go and h2o and is getting into the ballpark of cppsp (for serving a static "Hello World" page):
requests/s
go (1 thread) 29325
h2o (http 1.1, 4 threads) 46995
cppsp (1 thread) 60506
asynchttpserver before optimizations 13807
asynchttpserver with --gc:markandsweep 50358
asynchttpserver with --gc:boehm (single threaded) 51973
Ok, weird, I replied to this once, but it never posted.
Trying again!
@Orion, I'm trying to use your markdown library, but no matter how I try to use it, I keep getting: nimdmd.o: bad reloc address 0x40 in section '.rdata'
and
x86_64-w64-mingw32/bin/ld.exe: final link failed: Invalid operation
(I shortened the paths for clarity)
My guess is that something weird is going on with linking to the C markdown library.
What architecture are you on? I've gotten weird errors when I'm building a 64-bit program (the default on an x64 platform) and trying to link with a 32-bit library. Maybe your C markdown library is 32-bit, but Nim is building a 64-bit object?
That would make sense.
I've written about 20 lines of C, 10 years ago, so that world is all greek to me.
How would I build for 32-bit target?
How would I build for 32-bit target?
For gcc and clang this should work: nim c --passC:-m32 --passL:-m32 --cpu:i386 c file
ld.exe: cannot find -lmsvcrt Error: execution of an external program failed
Looking at the path, I'm assuming it can't find the 32 bit gcc, looking around for it. (Windows 7, GCC)
I grabbed a mingw that supposedly can do that, but no go.
I don't do C/C++ so I can't just modify/update/whatever the library to suit me either.
Hello Daimon,
I'm wondering how your web server was coming along?
I have been looking at various web server options for web app development.
I first played around with node.js for doing both client and server stuff, but to be honest I hate working with javascript.
I remember Nim from some of my search some time back and decided to see what would be involved in doing web app dev with Nim as the server.
So I guess I'm just wondering if you have examples of what server-side code looks like with your server? Does it handle routes? REST/Ajax?
(I'm just getting started in web development and learning as I'm going so I apologize if I'm not using the right terminology for describing certain things).
Regards